Submission #781237

# Submission time Handle Problem Language Result Execution time Memory
781237 2023-07-13T00:26:46 Z Deepesson Cubeword (CEOI19_cubeword) C++17
100 / 100
533 ms 18624 KB
#include <bits/stdc++.h>
#define SZ 63
using ll = long long;
ll rel[SZ][SZ];
ll tuplas[SZ][SZ][SZ];
ll MOD = 998244353;
std::map<char,int> mapinha;
int cur=0;
int valor(char ch){
	if(mapinha.find(ch)!=mapinha.end())return mapinha[ch];
	mapinha[ch]=cur;
	++cur;
	return mapinha[ch];
}
int main(){
	std::ios::sync_with_stdio(false);
	std::cin.tie(0);
	std::cout.tie(0);
	int N;
	std::cin>>N;
	std::map<std::string,bool> mapa[11];
	for(int i=0;i!=N;++i){
		std::string s;
		std::cin >> s;
		mapa[s.size()][s]=1;
		std::reverse(s.begin(),s.end());
		mapa[s.size()][s]=1;
	}
	ll ans=0;
	for(int j=3;j<=10;++j){
		for(auto&x:rel)for(auto&y:x)y=0;
		for(auto&x:mapa[j]){
			rel[valor(x.first[0])][valor(x.first.back())]++;
		}
		for(int i=0;i!=SZ;++i){
			for(int j=i;j!=SZ;++j){
				for(int k=j;k!=SZ;++k){
					ll tot=0;
					for(int u=0;u!=SZ;++u)tot=(tot+((rel[i][u]*rel[j][u]%MOD)*rel[k][u]))%MOD;
					tuplas[i][j][k]=tuplas[i][k][j]=tuplas[j][i][k]=tuplas[j][k][i]=tuplas[k][i][j]=tuplas[k][j][i]=tot;
				}
			}
		}
		for(int i=0;i!=SZ;++i){
			for(int j=i;j!=SZ;++j){
				for(int k=j;k!=SZ;++k){
					for(int l=k;l!=SZ;++l){
						ll peq = (((tuplas[i][j][k]*tuplas[i][k][l]%MOD)*tuplas[k][l][j]%MOD)*tuplas[i][j][l])%MOD;
						if(i!=j&&j!=k&&k!=l){
							ans=(ans+(24LL*peq))%MOD;
						}else {
							std::vector<int> arr={i,j,k,l};
							do{
								ans=(ans+(peq))%MOD;
							}while(std::next_permutation(arr.begin(),arr.end()));
						}
						
					}
				}
			}
		}
	}
	std::cout<<ans<<"\n";
}
# Verdict Execution time Memory Grader output
1 Correct 447 ms 17652 KB Output is correct
2 Correct 472 ms 17628 KB Output is correct
3 Correct 446 ms 17636 KB Output is correct
4 Correct 447 ms 17624 KB Output is correct
5 Correct 443 ms 17636 KB Output is correct
6 Correct 441 ms 17636 KB Output is correct
7 Correct 456 ms 17652 KB Output is correct
8 Correct 447 ms 17640 KB Output is correct
9 Correct 443 ms 17624 KB Output is correct
10 Correct 444 ms 17640 KB Output is correct
11 Correct 439 ms 17612 KB Output is correct
12 Correct 450 ms 17620 KB Output is correct
13 Correct 436 ms 17612 KB Output is correct
14 Correct 454 ms 17640 KB Output is correct
15 Correct 446 ms 17532 KB Output is correct
16 Correct 458 ms 17612 KB Output is correct
17 Correct 441 ms 17636 KB Output is correct
18 Correct 446 ms 17632 KB Output is correct
19 Correct 445 ms 17624 KB Output is correct
20 Correct 469 ms 17640 KB Output is correct
21 Correct 452 ms 17656 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 447 ms 17652 KB Output is correct
2 Correct 472 ms 17628 KB Output is correct
3 Correct 446 ms 17636 KB Output is correct
4 Correct 447 ms 17624 KB Output is correct
5 Correct 443 ms 17636 KB Output is correct
6 Correct 441 ms 17636 KB Output is correct
7 Correct 456 ms 17652 KB Output is correct
8 Correct 447 ms 17640 KB Output is correct
9 Correct 443 ms 17624 KB Output is correct
10 Correct 444 ms 17640 KB Output is correct
11 Correct 439 ms 17612 KB Output is correct
12 Correct 450 ms 17620 KB Output is correct
13 Correct 436 ms 17612 KB Output is correct
14 Correct 454 ms 17640 KB Output is correct
15 Correct 446 ms 17532 KB Output is correct
16 Correct 458 ms 17612 KB Output is correct
17 Correct 441 ms 17636 KB Output is correct
18 Correct 446 ms 17632 KB Output is correct
19 Correct 445 ms 17624 KB Output is correct
20 Correct 469 ms 17640 KB Output is correct
21 Correct 452 ms 17656 KB Output is correct
22 Correct 454 ms 18224 KB Output is correct
23 Correct 445 ms 18124 KB Output is correct
24 Correct 463 ms 18216 KB Output is correct
25 Correct 440 ms 18128 KB Output is correct
26 Correct 458 ms 18196 KB Output is correct
27 Correct 456 ms 18196 KB Output is correct
28 Correct 470 ms 18204 KB Output is correct
29 Correct 459 ms 18212 KB Output is correct
30 Correct 464 ms 18200 KB Output is correct
31 Correct 443 ms 18204 KB Output is correct
32 Correct 448 ms 18124 KB Output is correct
33 Correct 450 ms 18204 KB Output is correct
34 Correct 455 ms 18208 KB Output is correct
35 Correct 456 ms 18204 KB Output is correct
36 Correct 462 ms 18212 KB Output is correct
37 Correct 449 ms 18088 KB Output is correct
38 Correct 457 ms 18204 KB Output is correct
39 Correct 467 ms 18208 KB Output is correct
40 Correct 449 ms 18088 KB Output is correct
41 Correct 445 ms 18204 KB Output is correct
42 Correct 440 ms 18212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 447 ms 17652 KB Output is correct
2 Correct 472 ms 17628 KB Output is correct
3 Correct 446 ms 17636 KB Output is correct
4 Correct 447 ms 17624 KB Output is correct
5 Correct 443 ms 17636 KB Output is correct
6 Correct 441 ms 17636 KB Output is correct
7 Correct 456 ms 17652 KB Output is correct
8 Correct 447 ms 17640 KB Output is correct
9 Correct 443 ms 17624 KB Output is correct
10 Correct 444 ms 17640 KB Output is correct
11 Correct 439 ms 17612 KB Output is correct
12 Correct 450 ms 17620 KB Output is correct
13 Correct 436 ms 17612 KB Output is correct
14 Correct 454 ms 17640 KB Output is correct
15 Correct 446 ms 17532 KB Output is correct
16 Correct 458 ms 17612 KB Output is correct
17 Correct 441 ms 17636 KB Output is correct
18 Correct 446 ms 17632 KB Output is correct
19 Correct 445 ms 17624 KB Output is correct
20 Correct 469 ms 17640 KB Output is correct
21 Correct 452 ms 17656 KB Output is correct
22 Correct 454 ms 18224 KB Output is correct
23 Correct 445 ms 18124 KB Output is correct
24 Correct 463 ms 18216 KB Output is correct
25 Correct 440 ms 18128 KB Output is correct
26 Correct 458 ms 18196 KB Output is correct
27 Correct 456 ms 18196 KB Output is correct
28 Correct 470 ms 18204 KB Output is correct
29 Correct 459 ms 18212 KB Output is correct
30 Correct 464 ms 18200 KB Output is correct
31 Correct 443 ms 18204 KB Output is correct
32 Correct 448 ms 18124 KB Output is correct
33 Correct 450 ms 18204 KB Output is correct
34 Correct 455 ms 18208 KB Output is correct
35 Correct 456 ms 18204 KB Output is correct
36 Correct 462 ms 18212 KB Output is correct
37 Correct 449 ms 18088 KB Output is correct
38 Correct 457 ms 18204 KB Output is correct
39 Correct 467 ms 18208 KB Output is correct
40 Correct 449 ms 18088 KB Output is correct
41 Correct 445 ms 18204 KB Output is correct
42 Correct 440 ms 18212 KB Output is correct
43 Correct 466 ms 18392 KB Output is correct
44 Correct 453 ms 18380 KB Output is correct
45 Correct 457 ms 18332 KB Output is correct
46 Correct 453 ms 18388 KB Output is correct
47 Correct 456 ms 18380 KB Output is correct
48 Correct 454 ms 18280 KB Output is correct
49 Correct 451 ms 18392 KB Output is correct
50 Correct 468 ms 18396 KB Output is correct
51 Correct 457 ms 18384 KB Output is correct
52 Correct 468 ms 18380 KB Output is correct
53 Correct 446 ms 18396 KB Output is correct
54 Correct 471 ms 18396 KB Output is correct
55 Correct 457 ms 18388 KB Output is correct
56 Correct 446 ms 18388 KB Output is correct
57 Correct 446 ms 18372 KB Output is correct
58 Correct 454 ms 18392 KB Output is correct
59 Correct 478 ms 18388 KB Output is correct
60 Correct 460 ms 18380 KB Output is correct
61 Correct 447 ms 18388 KB Output is correct
62 Correct 462 ms 18380 KB Output is correct
63 Correct 459 ms 18384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 447 ms 17652 KB Output is correct
2 Correct 472 ms 17628 KB Output is correct
3 Correct 446 ms 17636 KB Output is correct
4 Correct 447 ms 17624 KB Output is correct
5 Correct 443 ms 17636 KB Output is correct
6 Correct 441 ms 17636 KB Output is correct
7 Correct 456 ms 17652 KB Output is correct
8 Correct 447 ms 17640 KB Output is correct
9 Correct 443 ms 17624 KB Output is correct
10 Correct 444 ms 17640 KB Output is correct
11 Correct 439 ms 17612 KB Output is correct
12 Correct 450 ms 17620 KB Output is correct
13 Correct 436 ms 17612 KB Output is correct
14 Correct 454 ms 17640 KB Output is correct
15 Correct 446 ms 17532 KB Output is correct
16 Correct 458 ms 17612 KB Output is correct
17 Correct 441 ms 17636 KB Output is correct
18 Correct 446 ms 17632 KB Output is correct
19 Correct 445 ms 17624 KB Output is correct
20 Correct 469 ms 17640 KB Output is correct
21 Correct 452 ms 17656 KB Output is correct
22 Correct 454 ms 18224 KB Output is correct
23 Correct 445 ms 18124 KB Output is correct
24 Correct 463 ms 18216 KB Output is correct
25 Correct 440 ms 18128 KB Output is correct
26 Correct 458 ms 18196 KB Output is correct
27 Correct 456 ms 18196 KB Output is correct
28 Correct 470 ms 18204 KB Output is correct
29 Correct 459 ms 18212 KB Output is correct
30 Correct 464 ms 18200 KB Output is correct
31 Correct 443 ms 18204 KB Output is correct
32 Correct 448 ms 18124 KB Output is correct
33 Correct 450 ms 18204 KB Output is correct
34 Correct 455 ms 18208 KB Output is correct
35 Correct 456 ms 18204 KB Output is correct
36 Correct 462 ms 18212 KB Output is correct
37 Correct 449 ms 18088 KB Output is correct
38 Correct 457 ms 18204 KB Output is correct
39 Correct 467 ms 18208 KB Output is correct
40 Correct 449 ms 18088 KB Output is correct
41 Correct 445 ms 18204 KB Output is correct
42 Correct 440 ms 18212 KB Output is correct
43 Correct 466 ms 18392 KB Output is correct
44 Correct 453 ms 18380 KB Output is correct
45 Correct 457 ms 18332 KB Output is correct
46 Correct 453 ms 18388 KB Output is correct
47 Correct 456 ms 18380 KB Output is correct
48 Correct 454 ms 18280 KB Output is correct
49 Correct 451 ms 18392 KB Output is correct
50 Correct 468 ms 18396 KB Output is correct
51 Correct 457 ms 18384 KB Output is correct
52 Correct 468 ms 18380 KB Output is correct
53 Correct 446 ms 18396 KB Output is correct
54 Correct 471 ms 18396 KB Output is correct
55 Correct 457 ms 18388 KB Output is correct
56 Correct 446 ms 18388 KB Output is correct
57 Correct 446 ms 18372 KB Output is correct
58 Correct 454 ms 18392 KB Output is correct
59 Correct 478 ms 18388 KB Output is correct
60 Correct 460 ms 18380 KB Output is correct
61 Correct 447 ms 18388 KB Output is correct
62 Correct 462 ms 18380 KB Output is correct
63 Correct 459 ms 18384 KB Output is correct
64 Correct 494 ms 18620 KB Output is correct
65 Correct 490 ms 18612 KB Output is correct
66 Correct 501 ms 18620 KB Output is correct
67 Correct 511 ms 18620 KB Output is correct
68 Correct 498 ms 18624 KB Output is correct
69 Correct 485 ms 18616 KB Output is correct
70 Correct 533 ms 18616 KB Output is correct
71 Correct 522 ms 18616 KB Output is correct
72 Correct 485 ms 18624 KB Output is correct
73 Correct 502 ms 18612 KB Output is correct
74 Correct 499 ms 18624 KB Output is correct
75 Correct 486 ms 18620 KB Output is correct
76 Correct 492 ms 18608 KB Output is correct
77 Correct 508 ms 18612 KB Output is correct
78 Correct 485 ms 18608 KB Output is correct
79 Correct 490 ms 18616 KB Output is correct
80 Correct 516 ms 18620 KB Output is correct
81 Correct 503 ms 18624 KB Output is correct
82 Correct 501 ms 18616 KB Output is correct
83 Correct 513 ms 18620 KB Output is correct
84 Correct 514 ms 18488 KB Output is correct