SRM562 Div1 Easy(250)

PastingPaintingDivOne

ある程度繰り返せば、ピクセル数の変化は一定になる。

#include <string>
#include <vector>
using namespace std;

class PastingPaintingDivOne{public:
vector<long long> countColors( vector <string> clipboard, int T )
{
    int H = (int)clipboard.size();
    int W = (int)clipboard[0].size();
    const int N = 50;

    vector<string> B(H+N,string(W+N,'.'));
    vector<vector<long long> > C(N+1,vector<long long>(3));

    for ( int i=0; i<=N; i++ )
    {
        for ( int y=0; y<H+N; y++ )
        for ( int x=0; x<W+N; x++ )
            switch ( B[y][x] )
            {
            case 'R': C[i][0]++; break;
            case 'G': C[i][1]++; break;
            case 'B': C[i][2]++; break;
            }

        for ( int y=0; y<H; y++ )
        for ( int x=0; x<W; x++ )
            if ( clipboard[y][x]!='.' )
                B[y+i][x+i] = clipboard[y][x];
    }

    vector<long long> ans(3);
    if ( T<=N )
        ans = C[T];
    else
        for ( int i=0; i<3; i++ )
            ans[i] = C[N][i] + (C[N][i]-C[N-1][i])*(T-N);
    return ans;
}};