SRM562 Div2 Medium(500) PastingPaintingDivTwo

PastingPaintingDivTwo

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

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

class PastingPaintingDivTwo{public:
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<long long> C(N+1);

    for ( int i=0; i<=N; i++ )
    {
        for ( int y=0; y<H+N; y++ )
        for ( int x=0; x<W+N; x++ )
            if ( B[y][x]=='B' )
                C[i]++;

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

    return T<=N ? C[T] : C[N]+(C[N]-C[N-1])*(T-N);
}};