Task: | Niitty |
Sender: | maweiyin24562 |
Submission time: | 2024-10-31 12:18:06 +0200 |
Language: | C++ (C++11) |
Status: | READY |
Result: | 58 |
group | verdict | score |
---|---|---|
#1 | ACCEPTED | 4 |
#2 | ACCEPTED | 6 |
#3 | ACCEPTED | 10 |
#4 | ACCEPTED | 13 |
#5 | ACCEPTED | 25 |
#6 | TIME LIMIT EXCEEDED | 0 |
test | verdict | time | group | |
---|---|---|---|---|
#1 | ACCEPTED | 0.00 s | 1, 2, 3, 4, 5, 6 | details |
#2 | ACCEPTED | 0.00 s | 1, 2, 3, 4, 5, 6 | details |
#3 | ACCEPTED | 0.00 s | 1, 2, 3, 4, 5, 6 | details |
#4 | ACCEPTED | 0.00 s | 1, 2, 3, 4, 5, 6 | details |
#5 | ACCEPTED | 0.00 s | 1, 2, 3, 4, 5, 6 | details |
#6 | ACCEPTED | 0.00 s | 2, 3, 4, 5, 6 | details |
#7 | ACCEPTED | 0.00 s | 2, 3, 4, 5, 6 | details |
#8 | ACCEPTED | 0.00 s | 2, 3, 4, 5, 6 | details |
#9 | ACCEPTED | 0.00 s | 2, 3, 4, 5, 6 | details |
#10 | ACCEPTED | 0.01 s | 3, 4, 5, 6 | details |
#11 | ACCEPTED | 0.01 s | 3, 4, 5, 6 | details |
#12 | ACCEPTED | 0.01 s | 3, 4, 5, 6 | details |
#13 | ACCEPTED | 0.00 s | 3, 4, 5, 6 | details |
#14 | ACCEPTED | 0.04 s | 4, 5, 6 | details |
#15 | ACCEPTED | 0.07 s | 4, 5, 6 | details |
#16 | ACCEPTED | 0.04 s | 4, 5, 6 | details |
#17 | ACCEPTED | 0.01 s | 4, 5, 6 | details |
#18 | ACCEPTED | 0.26 s | 5, 6 | details |
#19 | ACCEPTED | 0.55 s | 5, 6 | details |
#20 | ACCEPTED | 0.23 s | 5, 6 | details |
#21 | ACCEPTED | 0.11 s | 5, 6 | details |
#22 | TIME LIMIT EXCEEDED | -- | 6 | details |
#23 | TIME LIMIT EXCEEDED | -- | 6 | details |
#24 | TIME LIMIT EXCEEDED | -- | 6 | details |
#25 | TIME LIMIT EXCEEDED | -- | 6 | details |
Code
#include <bits/stdc++.h> using namespace std; #define IC(c) (int)(c-'A') const int N=509; const int F=26; int n; int pre[N][N][F]; int compact[N][F]; //pre[i][j][c] : prefix sum //compact[j][c] for every array[top,btm] //the compacted prefix sum bool exi[F]; //do number c exists int sum(int x1,int y1,int x2,int y2,int id){ return pre[x2][y2][id]-pre[x1-1][y2][id]-pre[x2][y1-1][id]+pre[x1-1][y1-1][id]; } bool check(int x1,int y1,int x2,int y2){ if(exi[0]&&sum(x1,y1,x2,y2,0)==0)return 0; if(exi[1]&&sum(x1,y1,x2,y2,1)==0)return 0; if(exi[2]&&sum(x1,y1,x2,y2,2)==0)return 0; if(exi[3]&&sum(x1,y1,x2,y2,3)==0)return 0; if(exi[4]&&sum(x1,y1,x2,y2,4)==0)return 0; if(exi[5]&&sum(x1,y1,x2,y2,5)==0)return 0; if(exi[6]&&sum(x1,y1,x2,y2,6)==0)return 0; if(exi[7]&&sum(x1,y1,x2,y2,7)==0)return 0; if(exi[8]&&sum(x1,y1,x2,y2,8)==0)return 0; if(exi[9]&&sum(x1,y1,x2,y2,9)==0)return 0; if(exi[10]&&sum(x1,y1,x2,y2,10)==0)return 0; if(exi[11]&&sum(x1,y1,x2,y2,11)==0)return 0; if(exi[12]&&sum(x1,y1,x2,y2,12)==0)return 0; if(exi[13]&&sum(x1,y1,x2,y2,13)==0)return 0; if(exi[14]&&sum(x1,y1,x2,y2,14)==0)return 0; if(exi[15]&&sum(x1,y1,x2,y2,15)==0)return 0; if(exi[16]&&sum(x1,y1,x2,y2,16)==0)return 0; if(exi[17]&&sum(x1,y1,x2,y2,17)==0)return 0; if(exi[18]&&sum(x1,y1,x2,y2,18)==0)return 0; if(exi[19]&&sum(x1,y1,x2,y2,19)==0)return 0; if(exi[20]&&sum(x1,y1,x2,y2,20)==0)return 0; if(exi[21]&&sum(x1,y1,x2,y2,21)==0)return 0; if(exi[22]&&sum(x1,y1,x2,y2,22)==0)return 0; if(exi[23]&&sum(x1,y1,x2,y2,23)==0)return 0; if(exi[24]&&sum(x1,y1,x2,y2,24)==0)return 0; if(exi[25]&&sum(x1,y1,x2,y2,25)==0)return 0; return 1; } int cpc_sum(int l,int r,int id){ return compact[r][id]-compact[l-1][id]; } bool cpc_check(int l,int r){ if(exi[0]&&cpc_sum(l,r,0)==0)return 0; if(exi[1]&&cpc_sum(l,r,1)==0)return 0; if(exi[2]&&cpc_sum(l,r,2)==0)return 0; if(exi[3]&&cpc_sum(l,r,3)==0)return 0; if(exi[4]&&cpc_sum(l,r,4)==0)return 0; if(exi[5]&&cpc_sum(l,r,5)==0)return 0; if(exi[6]&&cpc_sum(l,r,6)==0)return 0; if(exi[7]&&cpc_sum(l,r,7)==0)return 0; if(exi[8]&&cpc_sum(l,r,8)==0)return 0; if(exi[9]&&cpc_sum(l,r,9)==0)return 0; if(exi[10]&&cpc_sum(l,r,10)==0)return 0; if(exi[11]&&cpc_sum(l,r,11)==0)return 0; if(exi[12]&&cpc_sum(l,r,12)==0)return 0; if(exi[13]&&cpc_sum(l,r,13)==0)return 0; if(exi[14]&&cpc_sum(l,r,14)==0)return 0; if(exi[15]&&cpc_sum(l,r,15)==0)return 0; if(exi[16]&&cpc_sum(l,r,16)==0)return 0; if(exi[17]&&cpc_sum(l,r,17)==0)return 0; if(exi[18]&&cpc_sum(l,r,18)==0)return 0; if(exi[19]&&cpc_sum(l,r,19)==0)return 0; if(exi[20]&&cpc_sum(l,r,20)==0)return 0; if(exi[21]&&cpc_sum(l,r,21)==0)return 0; if(exi[22]&&cpc_sum(l,r,22)==0)return 0; if(exi[23]&&cpc_sum(l,r,23)==0)return 0; if(exi[24]&&cpc_sum(l,r,24)==0)return 0; if(exi[25]&&cpc_sum(l,r,25)==0)return 0; return true; } int ans; //sum up answer void Init(int i,int j,int id){ pre[i][j][0]=pre[i-1][j][0]+pre[i][j-1][0]-pre[i-1][j-1][0]; pre[i][j][1]=pre[i-1][j][1]+pre[i][j-1][1]-pre[i-1][j-1][1]; pre[i][j][2]=pre[i-1][j][2]+pre[i][j-1][2]-pre[i-1][j-1][2]; pre[i][j][3]=pre[i-1][j][3]+pre[i][j-1][3]-pre[i-1][j-1][3]; pre[i][j][4]=pre[i-1][j][4]+pre[i][j-1][4]-pre[i-1][j-1][4]; pre[i][j][5]=pre[i-1][j][5]+pre[i][j-1][5]-pre[i-1][j-1][5]; pre[i][j][6]=pre[i-1][j][6]+pre[i][j-1][6]-pre[i-1][j-1][6]; pre[i][j][7]=pre[i-1][j][7]+pre[i][j-1][7]-pre[i-1][j-1][7]; pre[i][j][8]=pre[i-1][j][8]+pre[i][j-1][8]-pre[i-1][j-1][8]; pre[i][j][9]=pre[i-1][j][9]+pre[i][j-1][9]-pre[i-1][j-1][9]; pre[i][j][10]=pre[i-1][j][10]+pre[i][j-1][10]-pre[i-1][j-1][10]; pre[i][j][11]=pre[i-1][j][11]+pre[i][j-1][11]-pre[i-1][j-1][11]; pre[i][j][12]=pre[i-1][j][12]+pre[i][j-1][12]-pre[i-1][j-1][12]; pre[i][j][13]=pre[i-1][j][13]+pre[i][j-1][13]-pre[i-1][j-1][13]; pre[i][j][14]=pre[i-1][j][14]+pre[i][j-1][14]-pre[i-1][j-1][14]; pre[i][j][15]=pre[i-1][j][15]+pre[i][j-1][15]-pre[i-1][j-1][15]; pre[i][j][16]=pre[i-1][j][16]+pre[i][j-1][16]-pre[i-1][j-1][16]; pre[i][j][17]=pre[i-1][j][17]+pre[i][j-1][17]-pre[i-1][j-1][17]; pre[i][j][18]=pre[i-1][j][18]+pre[i][j-1][18]-pre[i-1][j-1][18]; pre[i][j][19]=pre[i-1][j][19]+pre[i][j-1][19]-pre[i-1][j-1][19]; pre[i][j][20]=pre[i-1][j][20]+pre[i][j-1][20]-pre[i-1][j-1][20]; pre[i][j][21]=pre[i-1][j][21]+pre[i][j-1][21]-pre[i-1][j-1][21]; pre[i][j][22]=pre[i-1][j][22]+pre[i][j-1][22]-pre[i-1][j-1][22]; pre[i][j][23]=pre[i-1][j][23]+pre[i][j-1][23]-pre[i-1][j-1][23]; pre[i][j][24]=pre[i-1][j][24]+pre[i][j-1][24]-pre[i-1][j-1][24]; pre[i][j][25]=pre[i-1][j][25]+pre[i][j-1][25]-pre[i-1][j-1][25]; pre[i][j][id]++; } int main(){ cin>>n; for(int i=1;i<=n;i++) for(int j=1;j<=n;j++){ char c; cin>>c; int id=IC(c); exi[id]=true; Init(i,j,id); } //input ends here //for every [top,btm] in [1,n] for(int top=1;top<=n;top++){ for(int btm=top;btm<=n;btm++){//O(n^2) if(!check(top,1,btm,n))continue; int l=1,r=1; while(r<=n){ compact[r][0]=sum(top,1,btm,r,0); compact[r][1]=sum(top,1,btm,r,1); compact[r][2]=sum(top,1,btm,r,2); compact[r][3]=sum(top,1,btm,r,3); compact[r][4]=sum(top,1,btm,r,4); compact[r][5]=sum(top,1,btm,r,5); compact[r][6]=sum(top,1,btm,r,6); compact[r][7]=sum(top,1,btm,r,7); compact[r][8]=sum(top,1,btm,r,8); compact[r][9]=sum(top,1,btm,r,9); compact[r][10]=sum(top,1,btm,r,10); compact[r][11]=sum(top,1,btm,r,11); compact[r][12]=sum(top,1,btm,r,12); compact[r][13]=sum(top,1,btm,r,13); compact[r][14]=sum(top,1,btm,r,14); compact[r][15]=sum(top,1,btm,r,15); compact[r][16]=sum(top,1,btm,r,16); compact[r][17]=sum(top,1,btm,r,17); compact[r][18]=sum(top,1,btm,r,18); compact[r][19]=sum(top,1,btm,r,19); compact[r][20]=sum(top,1,btm,r,20); compact[r][21]=sum(top,1,btm,r,21); compact[r][22]=sum(top,1,btm,r,22); compact[r][23]=sum(top,1,btm,r,23); compact[r][24]=sum(top,1,btm,r,24); compact[r][25]=sum(top,1,btm,r,25); while(cpc_check(l+1,r)&&l<r){ l++; } if(cpc_check(l,r))ans+=l; r++; } } } cout<<ans<<endl; return 0; }
Test details
Test 1
Group: 1, 2, 3, 4, 5, 6
Verdict: ACCEPTED
input |
---|
10 TNCTNPNTPC NPPNTNTPTP NTNTTCNTCT NPCPNPPNTT ... |
correct output |
---|
2035 |
user output |
---|
2035 |
Test 2
Group: 1, 2, 3, 4, 5, 6
Verdict: ACCEPTED
input |
---|
10 NFWQLWNWYS DZOQJVXFPJ CNHXPXMCQD QRTBVNLTQC ... |
correct output |
---|
9 |
user output |
---|
9 |
Test 3
Group: 1, 2, 3, 4, 5, 6
Verdict: ACCEPTED
input |
---|
10 XXXXXXXXXX XXXXXXXXXX XXXXXXXXXX XXXXXXXXXX ... |
correct output |
---|
3025 |
user output |
---|
3025 |
Test 4
Group: 1, 2, 3, 4, 5, 6
Verdict: ACCEPTED
input |
---|
10 FFFFFFFFFF FFFFFCFFFF FFFFFFJFFF FFFFFFFFFF ... |
correct output |
---|
12 |
user output |
---|
12 |
Test 5
Group: 1, 2, 3, 4, 5, 6
Verdict: ACCEPTED
input |
---|
1 X |
correct output |
---|
1 |
user output |
---|
1 |
Test 6
Group: 2, 3, 4, 5, 6
Verdict: ACCEPTED
input |
---|
20 BBCBUBOUOBBCUUBBCOUO BOUCOOCUBCOOOCOBOCUO UCCUUUOBCOCBCBUBUCOO BUOBUCUCUOOBCOOUBUOO ... |
correct output |
---|
38724 |
user output |
---|
38724 |
Test 7
Group: 2, 3, 4, 5, 6
Verdict: ACCEPTED
input |
---|
20 CBGLSHGZHYZDWBNDBJUG SMUXOJQYPXZDTMJUIWOJ XIDSTNBGHKRKOVUVMINB MTQGCFRUHQKALXRNCQGS ... |
correct output |
---|
8334 |
user output |
---|
8334 |
Test 8
Group: 2, 3, 4, 5, 6
Verdict: ACCEPTED
input |
---|
20 KKKKKKKKKKKKKKKKKKKK KKKKKKKKKKKKKKKKKKKK KKKKKKKKKKKKKKKKKKKK KKKKKKKKKKKKKKKKKKKK ... |
correct output |
---|
44100 |
user output |
---|
44100 |
Test 9
Group: 2, 3, 4, 5, 6
Verdict: ACCEPTED
input |
---|
20 AAAAAAAAXAAAAAAAAAAA AAAWAAAAAAAAAAAAAOAA AAAAAAAAAAAAAAAAAPAA AAAAAAAAKAAAAAAAAAAZ ... |
correct output |
---|
18 |
user output |
---|
18 |
Test 10
Group: 3, 4, 5, 6
Verdict: ACCEPTED
input |
---|
50 GRGREEEGREGXRXXEGXXREXGRRRGRRR... |
correct output |
---|
1584665 |
user output |
---|
1584665 |
Test 11
Group: 3, 4, 5, 6
Verdict: ACCEPTED
input |
---|
50 AITIISJUHCCRZNKSDCNQKYSQRINFWJ... |
correct output |
---|
1077746 |
user output |
---|
1077746 |
Test 12
Group: 3, 4, 5, 6
Verdict: ACCEPTED
input |
---|
50 OOOOOOOOOOOOOOOOOOOOOOOOOOOOOO... |
correct output |
---|
1625625 |
user output |
---|
1625625 |
Test 13
Group: 3, 4, 5, 6
Verdict: ACCEPTED
input |
---|
50 FFFFFFFFFFFFFFFFFFFFFFFFFFFFFF... |
correct output |
---|
1680 |
user output |
---|
1680 |
Test 14
Group: 4, 5, 6
Verdict: ACCEPTED
input |
---|
100 NNCMDCDDCCNNNDNCMMNCDCDCCDCDNM... |
correct output |
---|
25325366 |
user output |
---|
25325366 |
Test 15
Group: 4, 5, 6
Verdict: ACCEPTED
input |
---|
100 LIMQQIHASECROEVILNVULGWZJPPKOG... |
correct output |
---|
22342463 |
user output |
---|
22342463 |
Test 16
Group: 4, 5, 6
Verdict: ACCEPTED
input |
---|
100 TTTTTTTTTTTTTTTTTTTTTTTTTTTTTT... |
correct output |
---|
25502500 |
user output |
---|
25502500 |
Test 17
Group: 4, 5, 6
Verdict: ACCEPTED
input |
---|
100 QXQQQQQQQQQQQQQQQQQQQQQQQQQQQQ... |
correct output |
---|
25650 |
user output |
---|
25650 |
Test 18
Group: 5, 6
Verdict: ACCEPTED
input |
---|
200 NAANANMMKNKKAKMKMAKNKMNKMMNNAA... |
correct output |
---|
403292767 |
user output |
---|
403292767 |
Test 19
Group: 5, 6
Verdict: ACCEPTED
input |
---|
200 OMYWATTLURKQPTKEFMGGYAOONXWVSC... |
correct output |
---|
388111321 |
user output |
---|
388111321 |
Test 20
Group: 5, 6
Verdict: ACCEPTED
input |
---|
200 CCCCCCCCCCCCCCCCCCCCCCCCCCCCCC... |
correct output |
---|
404010000 |
user output |
---|
404010000 |
Test 21
Group: 5, 6
Verdict: ACCEPTED
input |
---|
200 LLLLLLLLLLLLLLLLLHLLLLLLLLLLLL... |
correct output |
---|
14159445 |
user output |
---|
14159445 |
Test 22
Group: 6
Verdict: TIME LIMIT EXCEEDED
input |
---|
500 VVHWVUHVHUWWWVUUUWVUUHUUWHWUVW... |
correct output |
---|
15683003812 |
user output |
---|
(empty) |
Test 23
Group: 6
Verdict: TIME LIMIT EXCEEDED
input |
---|
500 OIMZGEQSBMBDSDXSWRFNKSGFEBBTJE... |
correct output |
---|
15575906951 |
user output |
---|
(empty) |
Test 24
Group: 6
Verdict: TIME LIMIT EXCEEDED
input |
---|
500 IIIIIIIIIIIIIIIIIIIIIIIIIIIIII... |
correct output |
---|
15687562500 |
user output |
---|
(empty) |
Test 25
Group: 6
Verdict: TIME LIMIT EXCEEDED
input |
---|
500 WWWWWWWWWWWWWWWWWWWWWWWWWWWWWW... |
correct output |
---|
3058970930 |
user output |
---|
(empty) |