class PastingPaintingDivOne { public: vector<long long> countColors(vector <string> cb, int T) { while (cb.size() < cb[0].size()) { cb.push_back(string(cb[0].size(), '.')); } while (cb.size() > cb[0].size()) { for (int i = 0; i < cb.size(); ++i) { cb[i] += '.'; } } const int M = cb.size(); const int N = M * 2 + 10; char C[N][N]; fill(&C[0][0], &C[N - 1][N - 1] + 1, '.'); lli r, g, b; lli R, G, B; R = G = B = 0; r = g = b = 0; lli base; for (base = 0; base <= M && base < T; ++base) { for (int i = 0; i < M; ++i) { for (int j = 0; j < M; ++j) { if (cb[i][j] != '.') C[base + i][base + j] = cb[i][j]; } } r = g = b = 0; for (int i = 1; i < M; ++i) { r += (C[base][base + i] == 'R') + (C[base + i][base] == 'R'); g += (C[base][base + i] == 'G') + (C[base + i][base] == 'G'); b += (C[base][base + i] == 'B') + (C[base + i][base] == 'B'); } r += (C[base][base] == 'R'); g += (C[base][base] == 'G'); b += (C[base][base] == 'B'); R += r; G += g; B += b; } if (base < T) { R += (T - base) * r; G += (T - base) * g; B += (T - base) * b; } for (int i = 0; i < M; ++i) { for (int j = 0; j < M; ++j) { R += (lli)(C[base + i][base + j] == 'R'); G += (lli)(C[base + i][base + j] == 'G'); B += (lli)(C[base + i][base + j] == 'B'); } } vector<lli> ret; ret.push_back(R); ret.push_back(G); ret.push_back(B); return ret; } };
12/01/2012
SRM 562 Div1 Easy
250