某岛

… : "…アッカリ~ン . .. . " .. .
February 21, 2013

SRM 493

//}/* .................................................................................................................................. */

const int N = 109;

struct Int{
    int val;

    operator int() const{return val;}

    Int(int val = 0):val(val){
        val %= MOD; if (val < 0) val += MOD;
    }
    inline Int& operator +=(const Int& rhs){
        INC(val, rhs);
        return *this;
    }
    inline Int operator +(const Int& rhs) const{
        return sum(val, rhs.val);
    }
    inline Int operator -(const Int& rhs) const{
        return dff(val, rhs);
    }
};

Int F[2][2][N][N], S[2][2][N][N]; bool A[N][N];
int n, m;

Int SS(int b1, int b2, int x1, int x2, int y1, int y2){
    return S[b1][b2][x2+1][y2+1] - S[b1][b2][x2+1][y1] - S[b1][b2][x1][y2+1] + S[b1][b2][x1][y1];
}

class AmoebaDivOne {
public:
	int count(vector <string> T) {

	    n = SZ(T), m = SZ(T[0]); REP_2(i, j, n, m){
	        int t = isdigit(T[i][j]) ? T[i][j] - '0' : T[i][j] - 'a' + 10;
            A[2*i][2*j] = t & 1, A[2*i][2*j+1] = t & 2;
            A[2*i+1][2*j] = t & 4, A[2*i+1][2*j+1] = t & 8;
	    }

	    n <<= 1, m <<= 1; RST(F); Int res; REP(i, n){

            RST(S); REP_4(b1, b2, l, r, 2, 2, m, m) S[b1][b2][l+1][r+1] = S[b1][b2][l][r+1] + S[b1][b2][l+1][r] - S[b1][b2][l][r] + F[b1][b2][l][r];

            RST(F); REP(l, m) FOR(r, l, m){

                if (A[i][r]) break;

                F[0][0][l][r] = SS(0, 0, l, r, l, r) + Int(1);
                F[0][1][l][r] = SS(0, 0, l, r, r+1, m-1) + SS(0, 1, l, r, r, m-1);
                F[1][0][l][r] = SS(0, 0, 0, l-1, l, r) + SS(1, 0, 0, l, l, r);
                F[1][1][l][r] = SS(0, 0, 0, l-1, r+1, m-1) + SS(0, 1, 0, l-1, r, m-1) + SS(1, 0, 0, l, r+1, m-1) + SS(1, 1, 0, l, r, m-1);

                REP_2(b1, b2, 2, 2) res += F[b1][b2][l][r];
            }
		}

		return res;
	}
};


http://paste.ubuntu.com/1697761/

Brief description:

Analysis:

..
your code here. . .
..

External link:


http://www.hhanger.com/?p=740