01b4c419a6 2013-02-19 kinaba: #include <iostream> 01b4c419a6 2013-02-19 kinaba: #include <sstream> 01b4c419a6 2013-02-19 kinaba: #include <iomanip> 01b4c419a6 2013-02-19 kinaba: #include <vector> 01b4c419a6 2013-02-19 kinaba: #include <string> 01b4c419a6 2013-02-19 kinaba: #include <map> 01b4c419a6 2013-02-19 kinaba: #include <set> 01b4c419a6 2013-02-19 kinaba: #include <algorithm> 01b4c419a6 2013-02-19 kinaba: #include <numeric> 01b4c419a6 2013-02-19 kinaba: #include <iterator> 01b4c419a6 2013-02-19 kinaba: #include <functional> 01b4c419a6 2013-02-19 kinaba: #include <complex> 01b4c419a6 2013-02-19 kinaba: #include <queue> 01b4c419a6 2013-02-19 kinaba: #include <stack> 01b4c419a6 2013-02-19 kinaba: #include <cmath> 01b4c419a6 2013-02-19 kinaba: #include <cassert> 01b4c419a6 2013-02-19 kinaba: using namespace std; 01b4c419a6 2013-02-19 kinaba: typedef long long LL; 01b4c419a6 2013-02-19 kinaba: typedef long double LD; 01b4c419a6 2013-02-19 kinaba: typedef complex<LD> CMP; 01b4c419a6 2013-02-19 kinaba: 01b4c419a6 2013-02-19 kinaba: class RobotHerb { public: 01b4c419a6 2013-02-19 kinaba: long long getdist(int T, vector <int> a) 01b4c419a6 2013-02-19 kinaba: { 01b4c419a6 2013-02-19 kinaba: static const LL dx[] = {+1,0,-1,0}; 01b4c419a6 2013-02-19 kinaba: static const LL dy[] = {0,+1,0,-1}; 01b4c419a6 2013-02-19 kinaba: 01b4c419a6 2013-02-19 kinaba: LL x=0, y=0, d=0, xs[5]={}, ys[5]={}; 01b4c419a6 2013-02-19 kinaba: for(int i=0; i<4; ++i) 01b4c419a6 2013-02-19 kinaba: { 01b4c419a6 2013-02-19 kinaba: for(int k=0; k<a.size(); ++k) 01b4c419a6 2013-02-19 kinaba: { 01b4c419a6 2013-02-19 kinaba: x += dx[d%4] * a[k]; 01b4c419a6 2013-02-19 kinaba: y += dy[d%4] * a[k]; 01b4c419a6 2013-02-19 kinaba: d += a[k]; 01b4c419a6 2013-02-19 kinaba: } 01b4c419a6 2013-02-19 kinaba: xs[i+1] = x; 01b4c419a6 2013-02-19 kinaba: ys[i+1] = y; 01b4c419a6 2013-02-19 kinaba: } 01b4c419a6 2013-02-19 kinaba: x = (xs[4]-xs[0])*(T/4) + xs[T%4]; 01b4c419a6 2013-02-19 kinaba: y = (ys[4]-ys[0])*(T/4) + ys[T%4]; 01b4c419a6 2013-02-19 kinaba: return abs(x)+abs(y); 01b4c419a6 2013-02-19 kinaba: } 01b4c419a6 2013-02-19 kinaba: }; 01b4c419a6 2013-02-19 kinaba: 01b4c419a6 2013-02-19 kinaba: // BEGIN CUT HERE 01b4c419a6 2013-02-19 kinaba: #include <ctime> 01b4c419a6 2013-02-19 kinaba: double start_time; string timer() 01b4c419a6 2013-02-19 kinaba: { ostringstream os; os << " (" << int((clock()-start_time)/CLOCKS_PER_SEC*1000) << " msec)"; return os.str(); } 01b4c419a6 2013-02-19 kinaba: template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) 01b4c419a6 2013-02-19 kinaba: { os << "{ "; 01b4c419a6 2013-02-19 kinaba: for(typename vector<T>::const_iterator it=v.begin(); it!=v.end(); ++it) 01b4c419a6 2013-02-19 kinaba: os << '\"' << *it << '\"' << (it+1==v.end() ? "" : ", "); os << " }"; return os; } 01b4c419a6 2013-02-19 kinaba: void verify_case(const long long& Expected, const long long& Received) { 01b4c419a6 2013-02-19 kinaba: bool ok = (Expected == Received); 01b4c419a6 2013-02-19 kinaba: if(ok) cerr << "PASSED" << timer() << endl; else { cerr << "FAILED" << timer() << endl; 01b4c419a6 2013-02-19 kinaba: cerr << "\to: \"" << Expected << '\"' << endl << "\tx: \"" << Received << '\"' << endl; } } 01b4c419a6 2013-02-19 kinaba: #define CASE(N) {cerr << "Test Case #" << N << "..." << flush; start_time=clock(); 01b4c419a6 2013-02-19 kinaba: #define END verify_case(_, RobotHerb().getdist(T, a));} 01b4c419a6 2013-02-19 kinaba: int main(){ 01b4c419a6 2013-02-19 kinaba: 01b4c419a6 2013-02-19 kinaba: CASE(0) 01b4c419a6 2013-02-19 kinaba: int T = 1; 01b4c419a6 2013-02-19 kinaba: int a_[] = {1,2,3}; 01b4c419a6 2013-02-19 kinaba: vector <int> a(a_, a_+sizeof(a_)/sizeof(*a_)); 01b4c419a6 2013-02-19 kinaba: long long _ = 2LL; 01b4c419a6 2013-02-19 kinaba: END 01b4c419a6 2013-02-19 kinaba: CASE(1) 01b4c419a6 2013-02-19 kinaba: int T = 100; 01b4c419a6 2013-02-19 kinaba: int a_[] = {1}; 01b4c419a6 2013-02-19 kinaba: vector <int> a(a_, a_+sizeof(a_)/sizeof(*a_)); 01b4c419a6 2013-02-19 kinaba: long long _ = 0LL; 01b4c419a6 2013-02-19 kinaba: END 01b4c419a6 2013-02-19 kinaba: CASE(2) 01b4c419a6 2013-02-19 kinaba: int T = 5; 01b4c419a6 2013-02-19 kinaba: int a_[] = {1,1,2}; 01b4c419a6 2013-02-19 kinaba: vector <int> a(a_, a_+sizeof(a_)/sizeof(*a_)); 01b4c419a6 2013-02-19 kinaba: long long _ = 10LL; 01b4c419a6 2013-02-19 kinaba: END 01b4c419a6 2013-02-19 kinaba: CASE(3) 01b4c419a6 2013-02-19 kinaba: int T = 1000000000; 01b4c419a6 2013-02-19 kinaba: int a_[] = {100}; 01b4c419a6 2013-02-19 kinaba: vector <int> a(a_, a_+sizeof(a_)/sizeof(*a_)); 01b4c419a6 2013-02-19 kinaba: long long _ = 100000000000LL; 01b4c419a6 2013-02-19 kinaba: END 01b4c419a6 2013-02-19 kinaba: CASE(4) 01b4c419a6 2013-02-19 kinaba: int T = 570; 01b4c419a6 2013-02-19 kinaba: int a_[] = {2013,2,13,314,271,1414,1732}; 01b4c419a6 2013-02-19 kinaba: vector <int> a(a_, a_+sizeof(a_)/sizeof(*a_)); 01b4c419a6 2013-02-19 kinaba: long long _ = 4112LL; 01b4c419a6 2013-02-19 kinaba: END 01b4c419a6 2013-02-19 kinaba: /* 01b4c419a6 2013-02-19 kinaba: CASE(5) 01b4c419a6 2013-02-19 kinaba: int T = ; 01b4c419a6 2013-02-19 kinaba: int a_[] = ; 01b4c419a6 2013-02-19 kinaba: vector <int> a(a_, a_+sizeof(a_)/sizeof(*a_)); 01b4c419a6 2013-02-19 kinaba: long long _ = LL; 01b4c419a6 2013-02-19 kinaba: END 01b4c419a6 2013-02-19 kinaba: CASE(6) 01b4c419a6 2013-02-19 kinaba: int T = ; 01b4c419a6 2013-02-19 kinaba: int a_[] = ; 01b4c419a6 2013-02-19 kinaba: vector <int> a(a_, a_+sizeof(a_)/sizeof(*a_)); 01b4c419a6 2013-02-19 kinaba: long long _ = LL; 01b4c419a6 2013-02-19 kinaba: END 01b4c419a6 2013-02-19 kinaba: */ 01b4c419a6 2013-02-19 kinaba: } 01b4c419a6 2013-02-19 kinaba: // END CUT HERE