ADDED SRM/550-U/1A.cpp Index: SRM/550-U/1A.cpp ================================================================== --- SRM/550-U/1A.cpp +++ SRM/550-U/1A.cpp @@ -0,0 +1,186 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +using namespace std; +typedef long long LL; +typedef long double LD; +typedef complex CMP; + +class RotatingBot { public: + int minArea(vector moves) + { + if( moves.size() == 1 ) { + int w = moves[0]+1; + return w; + } + if( moves.size() == 2 ) { + int w = moves[0]+1; + int h = moves[1]+1; + return w*h; + } + if( moves.size() == 3 ) { + int w1 = moves[0]+1; + int h = moves[1]+1; + int w2 = moves[2]+1; + return max(w1,w2)*h; + } + if( moves.size() == 4 ) { + int w1 = moves[0]+1; + int h1 = moves[1]+1; + int w2 = moves[2]+1; + int h2 = moves[3]+1; + if( w1 > w2 ) + return -1; + if( w1 == w2 ) { + if( h1 <= h2 ) + return -1; + else + return w1*h1; + } + return w2*max(h1,h2); + } + + int w1 = moves[0]+1; + int h1 = moves[1]+1; + int w2 = moves[2]+1; + int h2 = moves[3]+1; + if( w1 > w2 ) + return -1; + if( w1 == w2 ) { + vector rm = simulate(w1, h1, 0, 0); + if( match(rm, moves) ) + return w1*h1; + else + return -1; + } else { + if( h2

rm = simulate(w2, h2, w2-w1, h2-h1); + if( match(rm, moves) ) + return w2*h2; + else + return -1; + } + } + + vector simulate(int w, int h, int x, int y) + { + vector moves; + vector< vector > vis(h, vector(w)); + int dx[]={+1,0,-1,0}; + int dy[]={0,+1,0,-1}; + int d = 0; + vis[y][x] = true; + for(;;) { + int cnt = 0; + for(;;) { + int xx=x+dx[d]; + int yy=y+dy[d]; + if( yy<0||h<=yy||xx<0||w<=xx||vis[yy][xx] ) + break; + y=yy, x=xx; + vis[y][x] = true; + ++cnt; + } + d = (d+1)%4; + if( cnt == 0 ) + break; + moves.push_back(cnt); + } + return moves; + } + + bool match(const vector& rm, const vector& m) + { + if(rm.size() < m.size()) + return false; + for(int i=0; i+1= m[m.size()-1]; + } +}; + +// BEGIN CUT HERE +#include +double start_time; string timer() + { ostringstream os; os << " (" << int((clock()-start_time)/CLOCKS_PER_SEC*1000) << " msec)"; return os.str(); } +template ostream& operator<<(ostream& os, const vector& v) + { os << "{ "; + for(typename vector::const_iterator it=v.begin(); it!=v.end(); ++it) + os << '\"' << *it << '\"' << (it+1==v.end() ? "" : ", "); os << " }"; return os; } +void verify_case(const int& Expected, const int& Received) { + bool ok = (Expected == Received); + if(ok) cerr << "PASSED" << timer() << endl; else { cerr << "FAILED" << timer() << endl; + cerr << "\to: \"" << Expected << '\"' << endl << "\tx: \"" << Received << '\"' << endl; } } +#define CASE(N) {cerr << "Test Case #" << N << "..." << flush; start_time=clock(); +#define END verify_case(_, RotatingBot().minArea(moves));} +int main(){ + +CASE(0) + int moves_[] = {15}; + vector moves(moves_, moves_+sizeof(moves_)/sizeof(*moves_)); + int _ = 16; +END +CASE(1) + int moves_[] = {3,10}; + vector moves(moves_, moves_+sizeof(moves_)/sizeof(*moves_)); + int _ = 44; +END +CASE(2) + int moves_[] = {1,1,1,1}; + vector moves(moves_, moves_+sizeof(moves_)/sizeof(*moves_)); + int _ = -1; +END +CASE(3) + int moves_[] = {9,5,11,10,11,4,10}; + vector moves(moves_, moves_+sizeof(moves_)/sizeof(*moves_)); + int _ = 132; +END +CASE(4) + int moves_[] = {12,1,27,14,27,12,26,11,25,10,24,9,23,8,22,7,21,6,20,5,19,4,18,3,17,2,16,1,15}; + vector moves(moves_, moves_+sizeof(moves_)/sizeof(*moves_)); + int _ = 420; +END +CASE(5) + int moves_[] = {8,6,6,1}; + vector moves(moves_, moves_+sizeof(moves_)/sizeof(*moves_)); + int _ = -1; +END +CASE(6) + int moves_[] = {8,6,6}; + vector moves(moves_, moves_+sizeof(moves_)/sizeof(*moves_)); + int _ = 63; +END +CASE(7) + int moves_[] = {5,4,5,3,3}; + vector moves(moves_, moves_+sizeof(moves_)/sizeof(*moves_)); + int _ = 30; +END +CASE(8) +int moves_[] = {2,2,2,1}; + vector moves(moves_, moves_+sizeof(moves_)/sizeof(*moves_)); + int _ = 9; +END +/* +CASE(9) + int moves_[] = ; + vector moves(moves_, moves_+sizeof(moves_)/sizeof(*moves_)); + int _ = ; +END +*/ +} +// END CUT HERE ADDED SRM/550-U/1B.cpp Index: SRM/550-U/1B.cpp ================================================================== --- SRM/550-U/1B.cpp +++ SRM/550-U/1B.cpp @@ -0,0 +1,126 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +using namespace std; +typedef long long LL; +typedef long double LD; +typedef complex CMP; + +class CheckerExpansion { public: + vector resultAfter(long long t, long long x0, long long y0, int w, int h) + { + vector answer(h, string(w, '.')); + for(int y_=0; y_ +double start_time; string timer() + { ostringstream os; os << " (" << int((clock()-start_time)/CLOCKS_PER_SEC*1000) << " msec)"; return os.str(); } +template ostream& operator<<(ostream& os, const vector& v) + { os << "{ "; + for(typename vector::const_iterator it=v.begin(); it!=v.end(); ++it) + os << '\"' << *it << '\"' << (it+1==v.end() ? "" : ", "); os << " }"; return os; } +void verify_case(const vector & Expected, const vector & Received) { + bool ok = (Expected == Received); + if(ok) cerr << "PASSED" << timer() << endl; else { cerr << "FAILED" << timer() << endl; + cerr << "\to: " << Expected << endl << "\tx: " << Received << endl; } } +#define CASE(N) {cerr << "Test Case #" << N << "..." << flush; start_time=clock(); +#define END verify_case(_, CheckerExpansion().resultAfter(t, x0, y0, w, h));} +int main(){ + +CASE(0) + long long t = 1LL; + long long x0 = 0LL; + long long y0 = 0LL; + int w = 4; + int h = 4; + string __[] = {"....", "....", "....", "A..." }; + vector _(__, __+sizeof(__)/sizeof(*__)); +END +CASE(1) + long long t = 5LL; + long long x0 = 4LL; + long long y0 = 1LL; + int w = 3; + int h = 4; + string __[] = {"A..", "...", "B..", ".B." }; + vector _(__, __+sizeof(__)/sizeof(*__)); +END +CASE(2) + long long t = 1024LL; + long long x0 = 1525LL; + long long y0 = 512LL; + int w = 20; + int h = 2; + string __[] = {"B...B...B...........", ".B.A.B.A.B.........." }; + vector _(__, __+sizeof(__)/sizeof(*__)); +END +CASE(3) + long long t = 53LL; + long long x0 = 85LL; + long long y0 = 6LL; + int w = 5; + int h = 14; + string __[] = {".....", ".....", "B....", ".B.A.", ".....", ".....", ".....", ".....", ".....", ".....", "B....", ".B...", "..B..", ".A.B." }; + vector _(__, __+sizeof(__)/sizeof(*__)); +END +CASE(4) + long long t = 1000000000000LL; + long long x0 = 1000000000000LL; + long long y0 = 123456789123LL; + int w = 50; + int h = 50; + string __[] = {"?"}; + vector _(__, __+sizeof(__)/sizeof(*__)); +END +/* +CASE(5) + long long t = LL; + long long x0 = LL; + long long y0 = LL; + int w = ; + int h = ; + string __[] = ; + vector _(__, __+sizeof(__)/sizeof(*__)); +END +*/ +} +// END CUT HERE