CSES - Datatähti 2025 alku - Results
Submission details
Task:Niitty
Sender:maweiyin24562
Submission time:2024-10-31 12:15:15 +0200
Language:C++ (C++11)
Status:READY
Result:58
Feedback
groupverdictscore
#1ACCEPTED4
#2ACCEPTED6
#3ACCEPTED10
#4ACCEPTED13
#5ACCEPTED25
#60
Test results
testverdicttimegroup
#1ACCEPTED0.00 s1, 2, 3, 4, 5, 6details
#2ACCEPTED0.00 s1, 2, 3, 4, 5, 6details
#3ACCEPTED0.00 s1, 2, 3, 4, 5, 6details
#4ACCEPTED0.00 s1, 2, 3, 4, 5, 6details
#5ACCEPTED0.00 s1, 2, 3, 4, 5, 6details
#6ACCEPTED0.00 s2, 3, 4, 5, 6details
#7ACCEPTED0.00 s2, 3, 4, 5, 6details
#8ACCEPTED0.00 s2, 3, 4, 5, 6details
#9ACCEPTED0.00 s2, 3, 4, 5, 6details
#10ACCEPTED0.01 s3, 4, 5, 6details
#11ACCEPTED0.01 s3, 4, 5, 6details
#12ACCEPTED0.01 s3, 4, 5, 6details
#13ACCEPTED0.00 s3, 4, 5, 6details
#14ACCEPTED0.05 s4, 5, 6details
#15ACCEPTED0.07 s4, 5, 6details
#16ACCEPTED0.04 s4, 5, 6details
#17ACCEPTED0.01 s4, 5, 6details
#18ACCEPTED0.29 s5, 6details
#19ACCEPTED0.57 s5, 6details
#20ACCEPTED0.28 s5, 6details
#21ACCEPTED0.12 s5, 6details
#22--6details
#23--6details
#24--6details
#25--6details

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){
				for(int id=0;id<F;id++)
					compact[r][id]=sum(top,1,btm,r,id);
				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:

input
500
VVHWVUHVHUWWWVUUUWVUUHUUWHWUVW...

correct output
15683003812

user output
(empty)

Test 23

Group: 6

Verdict:

input
500
OIMZGEQSBMBDSDXSWRFNKSGFEBBTJE...

correct output
15575906951

user output
(empty)

Test 24

Group: 6

Verdict:

input
500
IIIIIIIIIIIIIIIIIIIIIIIIIIIIII...

correct output
15687562500

user output
(empty)

Test 25

Group: 6

Verdict:

input
500
WWWWWWWWWWWWWWWWWWWWWWWWWWWWWW...

correct output
3058970930

user output
(empty)