fa7992ffc5 2012-08-06 kinaba: #include <iostream> fa7992ffc5 2012-08-06 kinaba: #include <sstream> fa7992ffc5 2012-08-06 kinaba: #include <iomanip> fa7992ffc5 2012-08-06 kinaba: #include <vector> fa7992ffc5 2012-08-06 kinaba: #include <string> fa7992ffc5 2012-08-06 kinaba: #include <map> fa7992ffc5 2012-08-06 kinaba: #include <set> fa7992ffc5 2012-08-06 kinaba: #include <algorithm> fa7992ffc5 2012-08-06 kinaba: #include <numeric> fa7992ffc5 2012-08-06 kinaba: #include <iterator> fa7992ffc5 2012-08-06 kinaba: #include <functional> fa7992ffc5 2012-08-06 kinaba: #include <complex> fa7992ffc5 2012-08-06 kinaba: #include <queue> fa7992ffc5 2012-08-06 kinaba: #include <stack> fa7992ffc5 2012-08-06 kinaba: #include <cmath> fa7992ffc5 2012-08-06 kinaba: #include <cassert> fa7992ffc5 2012-08-06 kinaba: using namespace std; fa7992ffc5 2012-08-06 kinaba: typedef long long LL; fa7992ffc5 2012-08-06 kinaba: typedef long double LD; fa7992ffc5 2012-08-06 kinaba: typedef complex<LD> CMP; fa7992ffc5 2012-08-06 kinaba: fa7992ffc5 2012-08-06 kinaba: class CheckerExpansion { public: fa7992ffc5 2012-08-06 kinaba: vector <string> resultAfter(long long t, long long x0, long long y0, int w, int h) fa7992ffc5 2012-08-06 kinaba: { fa7992ffc5 2012-08-06 kinaba: vector<string> answer(h, string(w, '.')); fa7992ffc5 2012-08-06 kinaba: for(int y_=0; y_<h; ++y_) fa7992ffc5 2012-08-06 kinaba: for(int x_=0; x_<w; ++x_) { fa7992ffc5 2012-08-06 kinaba: LL y = y0 + y_; fa7992ffc5 2012-08-06 kinaba: LL x = x0 + x_; fa7992ffc5 2012-08-06 kinaba: if( (y+x)%2==1 ) fa7992ffc5 2012-08-06 kinaba: continue; fa7992ffc5 2012-08-06 kinaba: LL N = (y+x)/2; fa7992ffc5 2012-08-06 kinaba: if( t <= N ) fa7992ffc5 2012-08-06 kinaba: continue; fa7992ffc5 2012-08-06 kinaba: LL k = x-N; fa7992ffc5 2012-08-06 kinaba: if( k<0 || N<k ) fa7992ffc5 2012-08-06 kinaba: continue; fa7992ffc5 2012-08-06 kinaba: if( is_comb_odd(N,k) ) fa7992ffc5 2012-08-06 kinaba: answer[h-y_-1][x_] = (N%2==0 ? 'A' : 'B'); fa7992ffc5 2012-08-06 kinaba: } fa7992ffc5 2012-08-06 kinaba: return answer; fa7992ffc5 2012-08-06 kinaba: } fa7992ffc5 2012-08-06 kinaba: fa7992ffc5 2012-08-06 kinaba: bool is_comb_odd(LL n, LL k) fa7992ffc5 2012-08-06 kinaba: { fa7992ffc5 2012-08-06 kinaba: for(LL m=1; m<=n; m<<=1) fa7992ffc5 2012-08-06 kinaba: if( (k&m) && !(n&m) ) fa7992ffc5 2012-08-06 kinaba: return false; fa7992ffc5 2012-08-06 kinaba: return true; fa7992ffc5 2012-08-06 kinaba: } fa7992ffc5 2012-08-06 kinaba: }; fa7992ffc5 2012-08-06 kinaba: fa7992ffc5 2012-08-06 kinaba: // BEGIN CUT HERE fa7992ffc5 2012-08-06 kinaba: #include <ctime> fa7992ffc5 2012-08-06 kinaba: double start_time; string timer() fa7992ffc5 2012-08-06 kinaba: { ostringstream os; os << " (" << int((clock()-start_time)/CLOCKS_PER_SEC*1000) << " msec)"; return os.str(); } fa7992ffc5 2012-08-06 kinaba: template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) fa7992ffc5 2012-08-06 kinaba: { os << "{ "; fa7992ffc5 2012-08-06 kinaba: for(typename vector<T>::const_iterator it=v.begin(); it!=v.end(); ++it) fa7992ffc5 2012-08-06 kinaba: os << '\"' << *it << '\"' << (it+1==v.end() ? "" : ", "); os << " }"; return os; } fa7992ffc5 2012-08-06 kinaba: void verify_case(const vector <string>& Expected, const vector <string>& Received) { fa7992ffc5 2012-08-06 kinaba: bool ok = (Expected == Received); fa7992ffc5 2012-08-06 kinaba: if(ok) cerr << "PASSED" << timer() << endl; else { cerr << "FAILED" << timer() << endl; fa7992ffc5 2012-08-06 kinaba: cerr << "\to: " << Expected << endl << "\tx: " << Received << endl; } } fa7992ffc5 2012-08-06 kinaba: #define CASE(N) {cerr << "Test Case #" << N << "..." << flush; start_time=clock(); fa7992ffc5 2012-08-06 kinaba: #define END verify_case(_, CheckerExpansion().resultAfter(t, x0, y0, w, h));} fa7992ffc5 2012-08-06 kinaba: int main(){ fa7992ffc5 2012-08-06 kinaba: fa7992ffc5 2012-08-06 kinaba: CASE(0) fa7992ffc5 2012-08-06 kinaba: long long t = 1LL; fa7992ffc5 2012-08-06 kinaba: long long x0 = 0LL; fa7992ffc5 2012-08-06 kinaba: long long y0 = 0LL; fa7992ffc5 2012-08-06 kinaba: int w = 4; fa7992ffc5 2012-08-06 kinaba: int h = 4; fa7992ffc5 2012-08-06 kinaba: string __[] = {"....", "....", "....", "A..." }; fa7992ffc5 2012-08-06 kinaba: vector <string> _(__, __+sizeof(__)/sizeof(*__)); fa7992ffc5 2012-08-06 kinaba: END fa7992ffc5 2012-08-06 kinaba: CASE(1) fa7992ffc5 2012-08-06 kinaba: long long t = 5LL; fa7992ffc5 2012-08-06 kinaba: long long x0 = 4LL; fa7992ffc5 2012-08-06 kinaba: long long y0 = 1LL; fa7992ffc5 2012-08-06 kinaba: int w = 3; fa7992ffc5 2012-08-06 kinaba: int h = 4; fa7992ffc5 2012-08-06 kinaba: string __[] = {"A..", "...", "B..", ".B." }; fa7992ffc5 2012-08-06 kinaba: vector <string> _(__, __+sizeof(__)/sizeof(*__)); fa7992ffc5 2012-08-06 kinaba: END fa7992ffc5 2012-08-06 kinaba: CASE(2) fa7992ffc5 2012-08-06 kinaba: long long t = 1024LL; fa7992ffc5 2012-08-06 kinaba: long long x0 = 1525LL; fa7992ffc5 2012-08-06 kinaba: long long y0 = 512LL; fa7992ffc5 2012-08-06 kinaba: int w = 20; fa7992ffc5 2012-08-06 kinaba: int h = 2; fa7992ffc5 2012-08-06 kinaba: string __[] = {"B...B...B...........", ".B.A.B.A.B.........." }; fa7992ffc5 2012-08-06 kinaba: vector <string> _(__, __+sizeof(__)/sizeof(*__)); fa7992ffc5 2012-08-06 kinaba: END fa7992ffc5 2012-08-06 kinaba: CASE(3) fa7992ffc5 2012-08-06 kinaba: long long t = 53LL; fa7992ffc5 2012-08-06 kinaba: long long x0 = 85LL; fa7992ffc5 2012-08-06 kinaba: long long y0 = 6LL; fa7992ffc5 2012-08-06 kinaba: int w = 5; fa7992ffc5 2012-08-06 kinaba: int h = 14; fa7992ffc5 2012-08-06 kinaba: string __[] = {".....", ".....", "B....", ".B.A.", ".....", ".....", ".....", ".....", ".....", ".....", "B....", ".B...", "..B..", ".A.B." }; fa7992ffc5 2012-08-06 kinaba: vector <string> _(__, __+sizeof(__)/sizeof(*__)); fa7992ffc5 2012-08-06 kinaba: END fa7992ffc5 2012-08-06 kinaba: CASE(4) fa7992ffc5 2012-08-06 kinaba: long long t = 1000000000000LL; fa7992ffc5 2012-08-06 kinaba: long long x0 = 1000000000000LL; fa7992ffc5 2012-08-06 kinaba: long long y0 = 123456789123LL; fa7992ffc5 2012-08-06 kinaba: int w = 50; fa7992ffc5 2012-08-06 kinaba: int h = 50; fa7992ffc5 2012-08-06 kinaba: string __[] = {"?"}; fa7992ffc5 2012-08-06 kinaba: vector <string> _(__, __+sizeof(__)/sizeof(*__)); fa7992ffc5 2012-08-06 kinaba: END fa7992ffc5 2012-08-06 kinaba: /* fa7992ffc5 2012-08-06 kinaba: CASE(5) fa7992ffc5 2012-08-06 kinaba: long long t = LL; fa7992ffc5 2012-08-06 kinaba: long long x0 = LL; fa7992ffc5 2012-08-06 kinaba: long long y0 = LL; fa7992ffc5 2012-08-06 kinaba: int w = ; fa7992ffc5 2012-08-06 kinaba: int h = ; fa7992ffc5 2012-08-06 kinaba: string __[] = ; fa7992ffc5 2012-08-06 kinaba: vector <string> _(__, __+sizeof(__)/sizeof(*__)); fa7992ffc5 2012-08-06 kinaba: END fa7992ffc5 2012-08-06 kinaba: */ fa7992ffc5 2012-08-06 kinaba: } fa7992ffc5 2012-08-06 kinaba: // END CUT HERE