QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#878822#9695. Trash Problemucup-team5243#WA 0ms3712kbC++173.1kb2025-02-01 17:58:312025-02-01 17:58:45

Judging History

This is the latest submission verdict.

  • [2025-02-01 17:58:45]
  • Judged
  • Verdict: WA
  • Time: 0ms
  • Memory: 3712kb
  • [2025-02-01 17:58:31]
  • Submitted

answer


#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <bitset>
using i64 = long long;
using u64 = unsigned long long;
#define rep(i,n) for(int i=0; i<int(n); i++)
const i64 INF = 1001001001001001001;
template<typename A> void chmin(A& l, const A& r){ if(r < l) l = r; }
template<typename A> void chmax(A& l, const A& r){ if(l < r) l = r; }
using namespace std;

const int Z = 320;
using Bitset = bitset<Z+1>;

Bitset S0[301];
Bitset S1[301];
Bitset S[301];
Bitset X[301];
Bitset F[301];
Bitset XS[301];
Bitset D[301];
Bitset Lmask[301];


void testcase(){
    int N; cin >> N;
    vector<string> A(N); rep(i,N) cin >> A[i];
    for(int i=N-1; i>=0; i--){
        int c = 0;
        for(int j=N-1; j>=0; j--){
            if(A[i][j] == '1') c ^= 1;
            if(c) S0[i].set(j);
        }
        S0[i] ^= S0[i+1];
        S1[i] = ~S0[i];
    }
    rep(i,N) rep(j,N) if(A[i][j] == '0'){
        rep(f,2) rep(s,2) X[i+f].set(j+s);
    }
    rep(i,Z) rep(j,i) Lmask[i].set(j);
    //rep(i,N){ cout << S0[i] << endl; } cout << endl;
    //rep(i,N){ cout << S1[i] << endl; } cout << endl;
    //rep(i,N){ cout << X[i] << endl; } cout << endl;

    i64 ans = 0;

    for(int ry=1; ry<=N; ry++){
        for(int rx=1; rx<=N; rx++){
            //cout << "ry = " << ry << " , rx = " << rx << endl;
            rep(y,ry){
                int f = (S0[y].test(rx) ? 1 : 0) ^ (S0[ry].test(rx) ? 1 : 0);
                if(f) S[y] = S1[y]; else S[y] = S0[y];
                S[y] ^= S0[ry];
            }
            rep(y,ry) S[y] &= Lmask[rx];
            S[ry] = Bitset();
            rep(y,ry) F[y] = (S[y] >> 1) | S[y+1] | (S[y+1] >> 1);
            rep(y,ry) XS[y] = X[y] | F[y];
            rep(y,ry) XS[y] &= S[y];
            for(int y=ry-2; y>=0; y--) XS[y] |= XS[y+1];

            for(int y=ry-1; y>=0; y--) D[y] = D[y+1] | S[y];

            int border = rx;
            int c = 0;
            for(int ly=0; ly<ry; ly++){
                Bitset d = S[ly] | (S[ry] << 1);
                d.set(rx, false);
                d |= d >> 1;
                d |= d >> 2;
                d |= d >> 4;
                d |= d >> 8;
                d |= d >> 16;
                d |= d >> 32;
                d |= d >> 64;
                d |= d >> 128;
                d |= d >> 256;
                while(border > 0 && !XS[ly].test(border)) border--;
                int xborder = max(border, int(d.count()));
                //cout << "xborder = " << xborder << endl;
                c += (rx - xborder) - (D[ly] & ~Lmask[xborder]).count();
            }

            //rep(i,ry){ rep(j,rx){ cout << F[i].test(j); } cout << endl; }
            //cout << endl;
            //rep(i,ry){ rep(j,rx){ cout << XS[i].test(j); } cout << endl; }
            //cout << endl;
            //cout << "c = " << c << endl;

            ans += c;
        }
    }

    cout << ans << endl;
}

int main(){
    ios::sync_with_stdio(false); cin.tie(nullptr);
    testcase();
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 0ms
memory: 3712kb

input:

4
0110
0110
1111
1111

output:

-9540

result:

wrong answer 1st numbers differ - expected: '17', found: '-9540'