QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#878574 | #9695. Trash Problem | ucup-team5243# | RE | 1ms | 3712kb | C++17 | 2.9kb | 2025-02-01 16:05:08 | 2025-02-01 16:05:14 |
Judging History
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 = 10;
using Bitset = bitset<Z>;
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: -100
Runtime Error
input:
20 00110101100010111111 01000101010001111000 11101001001011011010 01000001001001101110 11100011001111111100 01101110111100111100 10000101011110110101 10001001101110000110 11110011110001110010 10001000101101011111 01000010001100110101 00111100100010011010 01000011000111011011 00111010111111010101 000...