155c399d58 2012-12-08 kinaba: #include <iostream> 155c399d58 2012-12-08 kinaba: #include <sstream> 155c399d58 2012-12-08 kinaba: #include <iomanip> 155c399d58 2012-12-08 kinaba: #include <vector> 155c399d58 2012-12-08 kinaba: #include <string> 155c399d58 2012-12-08 kinaba: #include <map> 155c399d58 2012-12-08 kinaba: #include <set> 155c399d58 2012-12-08 kinaba: #include <algorithm> 155c399d58 2012-12-08 kinaba: #include <numeric> 155c399d58 2012-12-08 kinaba: #include <iterator> 155c399d58 2012-12-08 kinaba: #include <functional> 155c399d58 2012-12-08 kinaba: #include <complex> 155c399d58 2012-12-08 kinaba: #include <queue> 155c399d58 2012-12-08 kinaba: #include <stack> 155c399d58 2012-12-08 kinaba: #include <cmath> 155c399d58 2012-12-08 kinaba: #include <cassert> 155c399d58 2012-12-08 kinaba: using namespace std; 155c399d58 2012-12-08 kinaba: typedef long long LL; 155c399d58 2012-12-08 kinaba: typedef long double LD; 155c399d58 2012-12-08 kinaba: typedef complex<LD> CMP; 155c399d58 2012-12-08 kinaba: 155c399d58 2012-12-08 kinaba: class PastingPaintingDivOne { public: 155c399d58 2012-12-08 kinaba: vector<long long> countColors(vector <string> c, int T) 155c399d58 2012-12-08 kinaba: { 155c399d58 2012-12-08 kinaba: int H = c.size(); 155c399d58 2012-12-08 kinaba: int W = c[0].size(); 155c399d58 2012-12-08 kinaba: 155c399d58 2012-12-08 kinaba: int TR = min(T, 50+T%50); 155c399d58 2012-12-08 kinaba: vector<string> shifted(H+TR+50, string(W+H, '.')); 155c399d58 2012-12-08 kinaba: 155c399d58 2012-12-08 kinaba: // TR 155c399d58 2012-12-08 kinaba: for(int i=0; i<TR; ++i) 155c399d58 2012-12-08 kinaba: for(int y=0; y<H; ++y) 155c399d58 2012-12-08 kinaba: for(int x=0; x<W; ++x) 155c399d58 2012-12-08 kinaba: if(c[y][x] != '.') 155c399d58 2012-12-08 kinaba: shifted[i+y][x+H-1-y] = c[y][x]; 155c399d58 2012-12-08 kinaba: 155c399d58 2012-12-08 kinaba: LL r=0, g=0, b=0; 155c399d58 2012-12-08 kinaba: for(int y=0; y<shifted.size(); ++y) 155c399d58 2012-12-08 kinaba: for(int x=0; x<shifted[y].size(); ++x) 155c399d58 2012-12-08 kinaba: if(shifted[y][x]=='R') r++; 155c399d58 2012-12-08 kinaba: else if(shifted[y][x]=='G') g++; 155c399d58 2012-12-08 kinaba: else if(shifted[y][x]=='B') b++; 155c399d58 2012-12-08 kinaba: 155c399d58 2012-12-08 kinaba: // 50 more 155c399d58 2012-12-08 kinaba: for(int i=TR; i<TR+50; ++i) 155c399d58 2012-12-08 kinaba: for(int y=0; y<H; ++y) 155c399d58 2012-12-08 kinaba: for(int x=0; x<W; ++x) 155c399d58 2012-12-08 kinaba: if(c[y][x] != '.') 155c399d58 2012-12-08 kinaba: shifted[i+y][x+H-1-y] = c[y][x]; 155c399d58 2012-12-08 kinaba: 155c399d58 2012-12-08 kinaba: LL rr=0, gg=0, bb=0; 155c399d58 2012-12-08 kinaba: for(int y=0; y<shifted.size(); ++y) 155c399d58 2012-12-08 kinaba: for(int x=0; x<shifted[y].size(); ++x) 155c399d58 2012-12-08 kinaba: if(shifted[y][x]=='R') rr++; 155c399d58 2012-12-08 kinaba: else if(shifted[y][x]=='G') gg++; 155c399d58 2012-12-08 kinaba: else if(shifted[y][x]=='B') bb++; 155c399d58 2012-12-08 kinaba: 155c399d58 2012-12-08 kinaba: vector<LL> answer; 155c399d58 2012-12-08 kinaba: answer.push_back((rr-r)*(T-TR)/50 + r); 155c399d58 2012-12-08 kinaba: answer.push_back((gg-g)*(T-TR)/50 + g); 155c399d58 2012-12-08 kinaba: answer.push_back((bb-b)*(T-TR)/50 + b); 155c399d58 2012-12-08 kinaba: return answer; 155c399d58 2012-12-08 kinaba: } 155c399d58 2012-12-08 kinaba: }; 155c399d58 2012-12-08 kinaba: 155c399d58 2012-12-08 kinaba: // BEGIN CUT HERE 155c399d58 2012-12-08 kinaba: #include <ctime> 155c399d58 2012-12-08 kinaba: double start_time; string timer() 155c399d58 2012-12-08 kinaba: { ostringstream os; os << " (" << int((clock()-start_time)/CLOCKS_PER_SEC*1000) << " msec)"; return os.str(); } 155c399d58 2012-12-08 kinaba: template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) 155c399d58 2012-12-08 kinaba: { os << "{ "; 155c399d58 2012-12-08 kinaba: for(typename vector<T>::const_iterator it=v.begin(); it!=v.end(); ++it) 155c399d58 2012-12-08 kinaba: os << '\"' << *it << '\"' << (it+1==v.end() ? "" : ", "); os << " }"; return os; } 155c399d58 2012-12-08 kinaba: void verify_case(const vector<long long>& Expected, const vector<long long>& Received) { 155c399d58 2012-12-08 kinaba: bool ok = (Expected == Received); 155c399d58 2012-12-08 kinaba: if(ok) cerr << "PASSED" << timer() << endl; else { cerr << "FAILED" << timer() << endl; 155c399d58 2012-12-08 kinaba: cerr << "\to: " << Expected << endl << "\tx: " << Received << endl; } } 155c399d58 2012-12-08 kinaba: #define CASE(N) {cerr << "Test Case #" << N << "..." << flush; start_time=clock(); 155c399d58 2012-12-08 kinaba: #define END verify_case(_, PastingPaintingDivOne().countColors(clipboard, T));} 155c399d58 2012-12-08 kinaba: int main(){ 155c399d58 2012-12-08 kinaba: 155c399d58 2012-12-08 kinaba: CASE(0) 155c399d58 2012-12-08 kinaba: string clipboard_[] = { 155c399d58 2012-12-08 kinaba: "..G", 155c399d58 2012-12-08 kinaba: "R..", 155c399d58 2012-12-08 kinaba: "BG." 155c399d58 2012-12-08 kinaba: }; 155c399d58 2012-12-08 kinaba: vector <string> clipboard(clipboard_, clipboard_+sizeof(clipboard_)/sizeof(*clipboard_)); 155c399d58 2012-12-08 kinaba: int T = 3; 155c399d58 2012-12-08 kinaba: long long __[] = {3, 4, 3 }; 155c399d58 2012-12-08 kinaba: vector<long long> _(__, __+sizeof(__)/sizeof(*__)); 155c399d58 2012-12-08 kinaba: END 155c399d58 2012-12-08 kinaba: CASE(1) 155c399d58 2012-12-08 kinaba: string clipboard_[] = { 155c399d58 2012-12-08 kinaba: "R...", 155c399d58 2012-12-08 kinaba: "....", 155c399d58 2012-12-08 kinaba: "....", 155c399d58 2012-12-08 kinaba: "...R" 155c399d58 2012-12-08 kinaba: }; 155c399d58 2012-12-08 kinaba: vector <string> clipboard(clipboard_, clipboard_+sizeof(clipboard_)/sizeof(*clipboard_)); 155c399d58 2012-12-08 kinaba: int T = 2; 155c399d58 2012-12-08 kinaba: long long __[] = {4, 0, 0 }; 155c399d58 2012-12-08 kinaba: vector<long long> _(__, __+sizeof(__)/sizeof(*__)); 155c399d58 2012-12-08 kinaba: END 155c399d58 2012-12-08 kinaba: CASE(2) 155c399d58 2012-12-08 kinaba: string clipboard_[] = {"RGB"}; 155c399d58 2012-12-08 kinaba: vector <string> clipboard(clipboard_, clipboard_+sizeof(clipboard_)/sizeof(*clipboard_)); 155c399d58 2012-12-08 kinaba: int T = 100000; 155c399d58 2012-12-08 kinaba: long long __[] = {100000, 100000, 100000 }; 155c399d58 2012-12-08 kinaba: vector<long long> _(__, __+sizeof(__)/sizeof(*__)); 155c399d58 2012-12-08 kinaba: END 155c399d58 2012-12-08 kinaba: CASE(3) 155c399d58 2012-12-08 kinaba: string clipboard_[] = {"."}; 155c399d58 2012-12-08 kinaba: vector <string> clipboard(clipboard_, clipboard_+sizeof(clipboard_)/sizeof(*clipboard_)); 155c399d58 2012-12-08 kinaba: int T = 1000000000; 155c399d58 2012-12-08 kinaba: long long __[] = {0, 0, 0 }; 155c399d58 2012-12-08 kinaba: vector<long long> _(__, __+sizeof(__)/sizeof(*__)); 155c399d58 2012-12-08 kinaba: END 155c399d58 2012-12-08 kinaba: CASE(4) 155c399d58 2012-12-08 kinaba: string clipboard_[] = { 155c399d58 2012-12-08 kinaba: "RB.", 155c399d58 2012-12-08 kinaba: ".G." 155c399d58 2012-12-08 kinaba: } 155c399d58 2012-12-08 kinaba: ; 155c399d58 2012-12-08 kinaba: vector <string> clipboard(clipboard_, clipboard_+sizeof(clipboard_)/sizeof(*clipboard_)); 155c399d58 2012-12-08 kinaba: int T = 100; 155c399d58 2012-12-08 kinaba: long long __[] = {100, 1, 100 }; 155c399d58 2012-12-08 kinaba: vector<long long> _(__, __+sizeof(__)/sizeof(*__)); 155c399d58 2012-12-08 kinaba: END 155c399d58 2012-12-08 kinaba: CASE(5) 155c399d58 2012-12-08 kinaba: string clipboard_[] = { 155c399d58 2012-12-08 kinaba: "..........G..........", 155c399d58 2012-12-08 kinaba: ".........G.G.........", 155c399d58 2012-12-08 kinaba: "........G...G........", 155c399d58 2012-12-08 kinaba: ".......G.....G.......", 155c399d58 2012-12-08 kinaba: "......G..B.B..G......", 155c399d58 2012-12-08 kinaba: ".....G...B.B...G.....", 155c399d58 2012-12-08 kinaba: "....G...........G....", 155c399d58 2012-12-08 kinaba: "...G...R.....R...G...", 155c399d58 2012-12-08 kinaba: "..G.....RRRRRR....G..", 155c399d58 2012-12-08 kinaba: ".G..........RR.....G.", 155c399d58 2012-12-08 kinaba: "GGGGGGGGGGGGGGGGGGGGG" 155c399d58 2012-12-08 kinaba: }; 155c399d58 2012-12-08 kinaba: vector <string> clipboard(clipboard_, clipboard_+sizeof(clipboard_)/sizeof(*clipboard_)); 155c399d58 2012-12-08 kinaba: int T = 1000000000; 155c399d58 2012-12-08 kinaba: long long __[] = {2000000018, 17000000048, 2000000005 }; 155c399d58 2012-12-08 kinaba: vector<long long> _(__, __+sizeof(__)/sizeof(*__)); 155c399d58 2012-12-08 kinaba: END 155c399d58 2012-12-08 kinaba: /* 155c399d58 2012-12-08 kinaba: CASE(6) 155c399d58 2012-12-08 kinaba: string clipboard_[] = ; 155c399d58 2012-12-08 kinaba: vector <string> clipboard(clipboard_, clipboard_+sizeof(clipboard_)/sizeof(*clipboard_)); 155c399d58 2012-12-08 kinaba: int T = ; 155c399d58 2012-12-08 kinaba: long long __[] = ; 155c399d58 2012-12-08 kinaba: vector<long long> _(__, __+sizeof(__)/sizeof(*__)); 155c399d58 2012-12-08 kinaba: END 155c399d58 2012-12-08 kinaba: CASE(7) 155c399d58 2012-12-08 kinaba: string clipboard_[] = ; 155c399d58 2012-12-08 kinaba: vector <string> clipboard(clipboard_, clipboard_+sizeof(clipboard_)/sizeof(*clipboard_)); 155c399d58 2012-12-08 kinaba: int T = ; 155c399d58 2012-12-08 kinaba: long long __[] = ; 155c399d58 2012-12-08 kinaba: vector<long long> _(__, __+sizeof(__)/sizeof(*__)); 155c399d58 2012-12-08 kinaba: END 155c399d58 2012-12-08 kinaba: */ 155c399d58 2012-12-08 kinaba: } 155c399d58 2012-12-08 kinaba: // END CUT HERE