cda9cb7744 2013-08-27 kinaba: #include <iostream> cda9cb7744 2013-08-27 kinaba: #include <sstream> cda9cb7744 2013-08-27 kinaba: #include <iomanip> cda9cb7744 2013-08-27 kinaba: #include <vector> cda9cb7744 2013-08-27 kinaba: #include <string> cda9cb7744 2013-08-27 kinaba: #include <map> cda9cb7744 2013-08-27 kinaba: #include <set> cda9cb7744 2013-08-27 kinaba: #include <algorithm> cda9cb7744 2013-08-27 kinaba: #include <numeric> cda9cb7744 2013-08-27 kinaba: #include <iterator> cda9cb7744 2013-08-27 kinaba: #include <functional> cda9cb7744 2013-08-27 kinaba: #include <complex> cda9cb7744 2013-08-27 kinaba: #include <queue> cda9cb7744 2013-08-27 kinaba: #include <stack> cda9cb7744 2013-08-27 kinaba: #include <cmath> cda9cb7744 2013-08-27 kinaba: #include <cassert> cda9cb7744 2013-08-27 kinaba: #include <tuple> cda9cb7744 2013-08-27 kinaba: using namespace std; cda9cb7744 2013-08-27 kinaba: typedef long long LL; cda9cb7744 2013-08-27 kinaba: typedef complex<double> CMP; cda9cb7744 2013-08-27 kinaba: cda9cb7744 2013-08-27 kinaba: class JumpFurther { public: cda9cb7744 2013-08-27 kinaba: int furthest(int N, int badStep) cda9cb7744 2013-08-27 kinaba: { cda9cb7744 2013-08-27 kinaba: int sigma = 0; cda9cb7744 2013-08-27 kinaba: for(int X=1; X<=N; ++X) cda9cb7744 2013-08-27 kinaba: { cda9cb7744 2013-08-27 kinaba: sigma += X; cda9cb7744 2013-08-27 kinaba: if(sigma == badStep) cda9cb7744 2013-08-27 kinaba: --sigma; cda9cb7744 2013-08-27 kinaba: } cda9cb7744 2013-08-27 kinaba: return sigma; cda9cb7744 2013-08-27 kinaba: } cda9cb7744 2013-08-27 kinaba: }; cda9cb7744 2013-08-27 kinaba: cda9cb7744 2013-08-27 kinaba: // BEGIN CUT HERE cda9cb7744 2013-08-27 kinaba: #include <ctime> cda9cb7744 2013-08-27 kinaba: double start_time; string timer() cda9cb7744 2013-08-27 kinaba: { ostringstream os; os << " (" << int((clock()-start_time)/CLOCKS_PER_SEC*1000) << " msec)"; return os.str(); } cda9cb7744 2013-08-27 kinaba: template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) cda9cb7744 2013-08-27 kinaba: { os << "{ "; cda9cb7744 2013-08-27 kinaba: for(typename vector<T>::const_iterator it=v.begin(); it!=v.end(); ++it) cda9cb7744 2013-08-27 kinaba: os << '\"' << *it << '\"' << (it+1==v.end() ? "" : ", "); os << " }"; return os; } cda9cb7744 2013-08-27 kinaba: void verify_case(const int& Expected, const int& Received) { cda9cb7744 2013-08-27 kinaba: bool ok = (Expected == Received); cda9cb7744 2013-08-27 kinaba: if(ok) cerr << "PASSED" << timer() << endl; else { cerr << "FAILED" << timer() << endl; cda9cb7744 2013-08-27 kinaba: cerr << "\to: \"" << Expected << '\"' << endl << "\tx: \"" << Received << '\"' << endl; } } cda9cb7744 2013-08-27 kinaba: #define CASE(N) {cerr << "Test Case #" << N << "..." << flush; start_time=clock(); cda9cb7744 2013-08-27 kinaba: #define END verify_case(_, JumpFurther().furthest(N, badStep));} cda9cb7744 2013-08-27 kinaba: int main(){ cda9cb7744 2013-08-27 kinaba: cda9cb7744 2013-08-27 kinaba: CASE(0) cda9cb7744 2013-08-27 kinaba: int N = 2; cda9cb7744 2013-08-27 kinaba: int badStep = 2; cda9cb7744 2013-08-27 kinaba: int _ = 3; cda9cb7744 2013-08-27 kinaba: END cda9cb7744 2013-08-27 kinaba: CASE(1) cda9cb7744 2013-08-27 kinaba: int N = 2; cda9cb7744 2013-08-27 kinaba: int badStep = 1; cda9cb7744 2013-08-27 kinaba: int _ = 2; cda9cb7744 2013-08-27 kinaba: END cda9cb7744 2013-08-27 kinaba: CASE(2) cda9cb7744 2013-08-27 kinaba: int N = 3; cda9cb7744 2013-08-27 kinaba: int badStep = 3; cda9cb7744 2013-08-27 kinaba: int _ = 5; cda9cb7744 2013-08-27 kinaba: END cda9cb7744 2013-08-27 kinaba: CASE(3) cda9cb7744 2013-08-27 kinaba: int N = 1313; cda9cb7744 2013-08-27 kinaba: int badStep = 5858; cda9cb7744 2013-08-27 kinaba: int _ = 862641; cda9cb7744 2013-08-27 kinaba: END cda9cb7744 2013-08-27 kinaba: CASE(4) cda9cb7744 2013-08-27 kinaba: int N = 1; cda9cb7744 2013-08-27 kinaba: int badStep = 757065; cda9cb7744 2013-08-27 kinaba: int _ = 1; cda9cb7744 2013-08-27 kinaba: END cda9cb7744 2013-08-27 kinaba: CASE(5) cda9cb7744 2013-08-27 kinaba: int N = 2000; cda9cb7744 2013-08-27 kinaba: int badStep = 123456; cda9cb7744 2013-08-27 kinaba: int _ = -1; cda9cb7744 2013-08-27 kinaba: END cda9cb7744 2013-08-27 kinaba: CASE(6) cda9cb7744 2013-08-27 kinaba: int N = 2000; cda9cb7744 2013-08-27 kinaba: int badStep = 3; cda9cb7744 2013-08-27 kinaba: int _ = -1; cda9cb7744 2013-08-27 kinaba: END cda9cb7744 2013-08-27 kinaba: CASE(7) cda9cb7744 2013-08-27 kinaba: int N = 2000; cda9cb7744 2013-08-27 kinaba: int badStep = 4000000; cda9cb7744 2013-08-27 kinaba: int _ = -1; cda9cb7744 2013-08-27 kinaba: END cda9cb7744 2013-08-27 kinaba: cda9cb7744 2013-08-27 kinaba: } cda9cb7744 2013-08-27 kinaba: // END CUT HERE