QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#878577#9695. Trash Problemucup-team5243#TL 18ms3840kbC++172.9kb2025-02-01 16:05:552025-02-01 16:05:55

Judging History

This is the latest submission verdict.

  • [2025-02-01 16:05:55]
  • Judged
  • Verdict: TL
  • Time: 18ms
  • Memory: 3840kb
  • [2025-02-01 16:05:55]
  • Submitted

answer

#ifdef NACHIA
#define _GLIBCXX_DEBUG
#else
#define NDEBUG
#endif
#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 = 300;
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);
                for(int x=1; x<=256; x*=2) d |= d >> x;
                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: 100
Accepted
time: 1ms
memory: 3712kb

input:

4
0110
0110
1111
1111

output:

17

result:

ok 1 number(s): "17"

Test #2:

score: 0
Accepted
time: 2ms
memory: 3840kb

input:

20
00110101100010111111
01000101010001111000
11101001001011011010
01000001001001101110
11100011001111111100
01101110111100111100
10000101011110110101
10001001101110000110
11110011110001110010
10001000101101011111
01000010001100110101
00111100100010011010
01000011000111011011
00111010111111010101
000...

output:

549

result:

ok 1 number(s): "549"

Test #3:

score: 0
Accepted
time: 2ms
memory: 3840kb

input:

20
01110011110110000110
10110000111010001100
01111100000001001010
11011111110110011001
01111001001010010111
00111001110110010001
01101011100101011111
10100001100011110001
00101111101011000011
11011011010110101001
01010011011110000111
11111100111100010110
00110111111010011111
00000011000100111011
011...

output:

591

result:

ok 1 number(s): "591"

Test #4:

score: 0
Accepted
time: 2ms
memory: 3840kb

input:

19
1000101101010111010
0001001000101010101
1101111101111110010
0100101100110101010
1111011000111010000
1010000111101101110
0001111010100011010
0011010011011111110
1110111011001001000
0001011010111111010
1010101100000110101
1000000011000111101
1101000011101001001
0011000100011110010
11100010000101001...

output:

558

result:

ok 1 number(s): "558"

Test #5:

score: 0
Accepted
time: 1ms
memory: 3840kb

input:

20
11011001111000000000
11011111111001100000
01111111101101101100
01111001101100111111
11000000011110110011
11000000011110001111
00011000111100111111
00011011111100110011
00011011011110011011
00011011011110011110
11110011110011000110
11110011110011011000
00001111011110011011
00111101111110111111
001...

output:

1629

result:

ok 1 number(s): "1629"

Test #6:

score: 0
Accepted
time: 2ms
memory: 3712kb

input:

20
00011000000001100011
00011110110111101111
11110110110111101100
11110011011111111000
01111011011110011000
01111000111100110000
01111000111100110000
01111011001101101100
11110011001101101100
11111100111101111110
00001111111101111110
00110011110000001100
00110011110111101100
01111011011111111110
011...

output:

1687

result:

ok 1 number(s): "1687"

Test #7:

score: 0
Accepted
time: 2ms
memory: 3712kb

input:

20
01100000000000000000
01100000000000000000
00000000011000000000
00011000011110000000
00011001100110000000
00000001100000000000
00000000110000110000
00000000110000111100
00000000110001101100
11000000110001100000
11001100110000000000
00001100110000000011
00000000000000000011
00000000000000000110
110...

output:

11708

result:

ok 1 number(s): "11708"

Test #8:

score: 0
Accepted
time: 1ms
memory: 3840kb

input:

20
00000000000000011000
00000000000000011000
00000000000000000000
00000000000000000000
00000000000000000000
00000000000000000000
00000000000000000000
00011000110001101100
00011000110001101100
00000000000000000000
00000000000000110000
00001100011000110110
00001100011000000110
00000110011000000011
000...

output:

15512

result:

ok 1 number(s): "15512"

Test #9:

score: 0
Accepted
time: 2ms
memory: 3840kb

input:

20
11001111000000000011
11001111000000000011
11110000001111110000
11110000001111110000
00000000001100110000
00000000001100110000
00000000000000000000
00000000000000000000
00110000000000001100
00110000000000001100
11000000001100000000
11000000001100000000
11000011000000000000
11000011000000000000
000...

output:

13034

result:

ok 1 number(s): "13034"

Test #10:

score: 0
Accepted
time: 2ms
memory: 3712kb

input:

20
00001100000000000000
00001100000000000000
00110011110011000000
00110011110011000000
11110000000000000000
11110000000000000000
11000000000000111100
11000000000000111100
11111100110000000000
11111100110000000000
00110000111111110011
00110000111111110011
00110011000000000000
00110011000000000000
000...

output:

9380

result:

ok 1 number(s): "9380"

Test #11:

score: 0
Accepted
time: 1ms
memory: 3840kb

input:

20
00110000000000000011
00110000000000000011
00000000000011001111
00000000000011001111
00110011000000111111
00110011000000111111
00001100110011110000
00001100110011110000
00001100001111000000
00001100001111000000
00110000001100000000
00110000001100000000
11000011110011000000
11000011110011000000
000...

output:

9048

result:

ok 1 number(s): "9048"

Test #12:

score: 0
Accepted
time: 0ms
memory: 3584kb

input:

20
00000011000000000000
00000011000000000000
00111111001111110011
00111111001111110011
11111100110000001100
11111100110000001100
11001100110000001100
11001100110000001100
11110000001100001100
11110000001100001100
00110000001100000000
00110000001100000000
00000000000011001100
00000000000011001100
000...

output:

9302

result:

ok 1 number(s): "9302"

Test #13:

score: 0
Accepted
time: 17ms
memory: 3840kb

input:

50
10110111111100111011110100110011011100011001010010
01101010010001101000110010101100011110101001011000
00011110101010110011100010101111111001010111101100
01010100110110111000100111110001111011111101010001
01010110110011010100110010100101001110110100111001
100011010011001011101000011110101001100111...

output:

4062

result:

ok 1 number(s): "4062"

Test #14:

score: 0
Accepted
time: 18ms
memory: 3840kb

input:

50
00000100101011100101110000000010000011011001100111
00111101010010100011011000010101101110011010111100
01110111001011001111001001010010110001000101100101
10111000100000000001011110101101001011000010111011
10111100111010111100010101001110101101101011011110
111110000110100001100001001111110011001001...

output:

4693

result:

ok 1 number(s): "4693"

Test #15:

score: 0
Accepted
time: 17ms
memory: 3840kb

input:

49
0000100110001000101010000110110000110110010001100
1011110001010000010011001110010000100101100011001
0000001000011111100001110111111100100100110110100
1010011111110000011100100000110001001001100011001
1100110001100011111010100110010111001100010110001
10011010111110001110011010100011010000110111011...

output:

4104

result:

ok 1 number(s): "4104"

Test #16:

score: 0
Accepted
time: 18ms
memory: 3840kb

input:

50
00000011000110110000011001111110110000000000000000
11000011000110111101111001111110110001111110111111
11000011000001101101111110011110011001111110111111
01111011000001100110011111111110011111101100011110
01111110001100110110000001100001111111101101111110
110111100011111100001111001100011110000011...

output:

11480

result:

ok 1 number(s): "11480"

Test #17:

score: 0
Accepted
time: 18ms
memory: 3840kb

input:

50
00011110000111111111111000000000000000000000000110
11011110011111111111111111100110111101111110000110
11001100011000110000011111100110111101111110000000
11001111110011111100011111100011111101100000001111
11110011111111001100000111111011111101101100001111
111100000011000001100110110110000001111011...

output:

12511

result:

ok 1 number(s): "12511"

Test #18:

score: 0
Accepted
time: 17ms
memory: 3840kb

input:

50
00000000000000000000000000000000001100000000000000
00000000011001100000000000000000001100000000000000
00000000011001100000000000000000000000000110000011
00000000000000000000000000000000011001100110000011
00000000000000000011000000000000011001100000000000
000000000000000000110000000000000000000000...

output:

517453

result:

ok 1 number(s): "517453"

Test #19:

score: 0
Accepted
time: 17ms
memory: 3840kb

input:

50
00000000000000000000000000000000000000000000011000
00000000000000000000000000000000000000000000011000
00000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000
000000000000110000000000000000000000000000...

output:

510978

result:

ok 1 number(s): "510978"

Test #20:

score: 0
Accepted
time: 17ms
memory: 3840kb

input:

50
00001100000011000000110011001111001100001100000011
00001100000011000000110011001111001100001100000011
11000011000000001100000000000011110000000000001100
11000011000000001100000000000011110000000000001100
00110000000000000000110000000011000000110011000000
001100000000000000001100000000110000001100...

output:

195043

result:

ok 1 number(s): "195043"

Test #21:

score: 0
Accepted
time: 17ms
memory: 3840kb

input:

50
00111100000000000000110000001100001100000011001100
00111100000000000000110000001100001100000011001100
11000000001100000000001111001111000011000000110000
11000000001100000000001111001111000011000000110000
00110000000000000000000000000000110000001100000000
001100000000000000000000000000001100000011...

output:

200866

result:

ok 1 number(s): "200866"

Test #22:

score: 0
Accepted
time: 16ms
memory: 3712kb

input:

50
00000000000000000000000000000000000000000011000011
00000000000000000000000000000000000000000011000011
00000000000000000000000000000000110000001100001100
00000000000000000000000000000000110000001100001100
00000000000000000000000000000000000000000000000000
000000000000000000000000000000000000000000...

output:

411379

result:

ok 1 number(s): "411379"

Test #23:

score: 0
Accepted
time: 18ms
memory: 3840kb

input:

50
00000000000000110000110000000000001100110000000000
00000000000000110000110000000000001100110000000000
00000000110000000000000011000000000000000000000011
00000000110000000000000011000000000000000000000011
00000000000000000000000000000000000000000000000000
000000000000000000000000000000000000000000...

output:

378461

result:

ok 1 number(s): "378461"

Test #24:

score: -100
Time Limit Exceeded

input:

300
00000000100001101110110010111001010000000101000011011100101110110110100000111110000011000100010111100000101110011011100000000011000001000000111010001110001110110111110011111000000010101111101110000001011101110111010101110001000011100110101010101101001111010011111010100111000100100010001011100010...

output:


result: