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