#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define fi first
#define se second
#define mp make_pair
#define fastIO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
const int AL = 62;
const int LEN = 11;
const int MOD = 998244353;
int cnt[AL][AL][LEN];
bool is_palin(string t){
for(int i = 0 ; i < t.size() ; i ++ ){
if(t[i] != t[(int)t.size() - 1 - i]){
return false;
}
}
return true;
}
int D[AL][AL][AL];
int mlt(int a, int b){
return (a * 1ll * b) % MOD;
}
void add(int &a, int b){
a = (a + b) % MOD;
}
int getid(char f){
if(f >= 'a' && f <= 'z') return f - 'a';
else if(f >= 'A' && f <= 'Z') return 26 + (f - 'A');
return 52 + f - '0';
}
map<string, bool> dict;
int perm[AL][AL][AL][AL];
int calc(vector<int> q){
sort(q.begin(), q.end());
int cnt = 0;
do{
cnt ++ ;
}while(next_permutation(q.begin(), q.end()));
return cnt;
}
int main(){
fastIO;
int n;
cin >> n;
string t;
int m;
int fa, fb;
for(int i = 0 ; i < n; i ++ ){
cin >> t;
m = t.size();
if(dict.count(t)) continue;
fa=getid(t[0]);
fb=getid(t.back());
cnt[fa][fb][m]++;
if(!is_palin(t)) cnt[fb][fa][m]++;
dict[t]=true;
reverse(t.begin(), t.end());
dict[t]=true;
}
for(int i = 0 ; i < AL; i ++ ){
for(int j = i ; j < AL; j ++ ){
for(int p = j ; p < AL; p ++ ){
for(int t = p ; t < AL; t ++ ){
perm[i][j][p][t]=calc({i,j,p,t});
}
}
}
}
int sol = 0;
for(int len = 3; len <= 10; len ++ ){
for(int i = 0 ; i < AL; i ++ ){
for(int j = i ; j < AL; j ++ ){
for(int k = j ; k < AL; k ++ ){
D[i][j][k]=0;
for(int q = 0; q < AL; q ++ ){
add(D[i][j][k],mlt(mlt(cnt[i][q][len],cnt[j][q][len]),cnt[k][q][len]));
}
}
}
}
for(int a = 0; a < AL; a ++ ){
for(int d = a ; d < AL; d ++ ){
for(int e = d; e < AL; e ++ ){
if(D[a][d][e] == 0) continue;
for(int h = e; h < AL; h ++ ){
add(sol,mlt(perm[a][d][e][h],mlt(mlt(D[a][d][e],D[a][d][h]),mlt(D[d][e][h],D[a][e][h]))));
}
}
}
}
}
cout << sol << "\n";
return 0;
}
Compilation message
cubeword.cpp: In function 'bool is_palin(std::string)':
cubeword.cpp:21:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
21 | for(int i = 0 ; i < t.size() ; i ++ ){
| ~~^~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
519 ms |
33240 KB |
Output is correct |
2 |
Correct |
517 ms |
33132 KB |
Output is correct |
3 |
Correct |
526 ms |
33260 KB |
Output is correct |
4 |
Correct |
521 ms |
33132 KB |
Output is correct |
5 |
Correct |
526 ms |
33004 KB |
Output is correct |
6 |
Correct |
524 ms |
33132 KB |
Output is correct |
7 |
Correct |
524 ms |
33200 KB |
Output is correct |
8 |
Correct |
523 ms |
33140 KB |
Output is correct |
9 |
Correct |
521 ms |
33132 KB |
Output is correct |
10 |
Correct |
519 ms |
33004 KB |
Output is correct |
11 |
Correct |
524 ms |
33260 KB |
Output is correct |
12 |
Correct |
537 ms |
33004 KB |
Output is correct |
13 |
Correct |
523 ms |
33132 KB |
Output is correct |
14 |
Correct |
516 ms |
33132 KB |
Output is correct |
15 |
Correct |
522 ms |
33132 KB |
Output is correct |
16 |
Correct |
527 ms |
33260 KB |
Output is correct |
17 |
Correct |
522 ms |
33004 KB |
Output is correct |
18 |
Correct |
522 ms |
33132 KB |
Output is correct |
19 |
Correct |
527 ms |
33132 KB |
Output is correct |
20 |
Correct |
523 ms |
33004 KB |
Output is correct |
21 |
Correct |
521 ms |
33004 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
519 ms |
33240 KB |
Output is correct |
2 |
Correct |
517 ms |
33132 KB |
Output is correct |
3 |
Correct |
526 ms |
33260 KB |
Output is correct |
4 |
Correct |
521 ms |
33132 KB |
Output is correct |
5 |
Correct |
526 ms |
33004 KB |
Output is correct |
6 |
Correct |
524 ms |
33132 KB |
Output is correct |
7 |
Correct |
524 ms |
33200 KB |
Output is correct |
8 |
Correct |
523 ms |
33140 KB |
Output is correct |
9 |
Correct |
521 ms |
33132 KB |
Output is correct |
10 |
Correct |
519 ms |
33004 KB |
Output is correct |
11 |
Correct |
524 ms |
33260 KB |
Output is correct |
12 |
Correct |
537 ms |
33004 KB |
Output is correct |
13 |
Correct |
523 ms |
33132 KB |
Output is correct |
14 |
Correct |
516 ms |
33132 KB |
Output is correct |
15 |
Correct |
522 ms |
33132 KB |
Output is correct |
16 |
Correct |
527 ms |
33260 KB |
Output is correct |
17 |
Correct |
522 ms |
33004 KB |
Output is correct |
18 |
Correct |
522 ms |
33132 KB |
Output is correct |
19 |
Correct |
527 ms |
33132 KB |
Output is correct |
20 |
Correct |
523 ms |
33004 KB |
Output is correct |
21 |
Correct |
521 ms |
33004 KB |
Output is correct |
22 |
Correct |
532 ms |
33816 KB |
Output is correct |
23 |
Correct |
533 ms |
33900 KB |
Output is correct |
24 |
Correct |
528 ms |
33772 KB |
Output is correct |
25 |
Correct |
530 ms |
33888 KB |
Output is correct |
26 |
Correct |
527 ms |
33772 KB |
Output is correct |
27 |
Correct |
523 ms |
33900 KB |
Output is correct |
28 |
Correct |
525 ms |
33736 KB |
Output is correct |
29 |
Correct |
519 ms |
33772 KB |
Output is correct |
30 |
Correct |
525 ms |
33836 KB |
Output is correct |
31 |
Correct |
530 ms |
33772 KB |
Output is correct |
32 |
Correct |
524 ms |
34028 KB |
Output is correct |
33 |
Correct |
527 ms |
33684 KB |
Output is correct |
34 |
Correct |
534 ms |
33708 KB |
Output is correct |
35 |
Correct |
528 ms |
33772 KB |
Output is correct |
36 |
Correct |
532 ms |
33748 KB |
Output is correct |
37 |
Correct |
535 ms |
33900 KB |
Output is correct |
38 |
Correct |
525 ms |
33900 KB |
Output is correct |
39 |
Correct |
524 ms |
33860 KB |
Output is correct |
40 |
Correct |
530 ms |
33704 KB |
Output is correct |
41 |
Correct |
528 ms |
33772 KB |
Output is correct |
42 |
Correct |
523 ms |
33900 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
519 ms |
33240 KB |
Output is correct |
2 |
Correct |
517 ms |
33132 KB |
Output is correct |
3 |
Correct |
526 ms |
33260 KB |
Output is correct |
4 |
Correct |
521 ms |
33132 KB |
Output is correct |
5 |
Correct |
526 ms |
33004 KB |
Output is correct |
6 |
Correct |
524 ms |
33132 KB |
Output is correct |
7 |
Correct |
524 ms |
33200 KB |
Output is correct |
8 |
Correct |
523 ms |
33140 KB |
Output is correct |
9 |
Correct |
521 ms |
33132 KB |
Output is correct |
10 |
Correct |
519 ms |
33004 KB |
Output is correct |
11 |
Correct |
524 ms |
33260 KB |
Output is correct |
12 |
Correct |
537 ms |
33004 KB |
Output is correct |
13 |
Correct |
523 ms |
33132 KB |
Output is correct |
14 |
Correct |
516 ms |
33132 KB |
Output is correct |
15 |
Correct |
522 ms |
33132 KB |
Output is correct |
16 |
Correct |
527 ms |
33260 KB |
Output is correct |
17 |
Correct |
522 ms |
33004 KB |
Output is correct |
18 |
Correct |
522 ms |
33132 KB |
Output is correct |
19 |
Correct |
527 ms |
33132 KB |
Output is correct |
20 |
Correct |
523 ms |
33004 KB |
Output is correct |
21 |
Correct |
521 ms |
33004 KB |
Output is correct |
22 |
Correct |
532 ms |
33816 KB |
Output is correct |
23 |
Correct |
533 ms |
33900 KB |
Output is correct |
24 |
Correct |
528 ms |
33772 KB |
Output is correct |
25 |
Correct |
530 ms |
33888 KB |
Output is correct |
26 |
Correct |
527 ms |
33772 KB |
Output is correct |
27 |
Correct |
523 ms |
33900 KB |
Output is correct |
28 |
Correct |
525 ms |
33736 KB |
Output is correct |
29 |
Correct |
519 ms |
33772 KB |
Output is correct |
30 |
Correct |
525 ms |
33836 KB |
Output is correct |
31 |
Correct |
530 ms |
33772 KB |
Output is correct |
32 |
Correct |
524 ms |
34028 KB |
Output is correct |
33 |
Correct |
527 ms |
33684 KB |
Output is correct |
34 |
Correct |
534 ms |
33708 KB |
Output is correct |
35 |
Correct |
528 ms |
33772 KB |
Output is correct |
36 |
Correct |
532 ms |
33748 KB |
Output is correct |
37 |
Correct |
535 ms |
33900 KB |
Output is correct |
38 |
Correct |
525 ms |
33900 KB |
Output is correct |
39 |
Correct |
524 ms |
33860 KB |
Output is correct |
40 |
Correct |
530 ms |
33704 KB |
Output is correct |
41 |
Correct |
528 ms |
33772 KB |
Output is correct |
42 |
Correct |
523 ms |
33900 KB |
Output is correct |
43 |
Correct |
528 ms |
34156 KB |
Output is correct |
44 |
Correct |
526 ms |
34156 KB |
Output is correct |
45 |
Correct |
530 ms |
34028 KB |
Output is correct |
46 |
Correct |
523 ms |
34204 KB |
Output is correct |
47 |
Correct |
529 ms |
34176 KB |
Output is correct |
48 |
Correct |
529 ms |
34028 KB |
Output is correct |
49 |
Correct |
527 ms |
34156 KB |
Output is correct |
50 |
Correct |
533 ms |
34284 KB |
Output is correct |
51 |
Correct |
526 ms |
34028 KB |
Output is correct |
52 |
Correct |
533 ms |
34284 KB |
Output is correct |
53 |
Correct |
530 ms |
34156 KB |
Output is correct |
54 |
Correct |
528 ms |
34028 KB |
Output is correct |
55 |
Correct |
538 ms |
34372 KB |
Output is correct |
56 |
Correct |
533 ms |
34156 KB |
Output is correct |
57 |
Correct |
536 ms |
34160 KB |
Output is correct |
58 |
Correct |
533 ms |
34028 KB |
Output is correct |
59 |
Correct |
529 ms |
34232 KB |
Output is correct |
60 |
Correct |
534 ms |
34156 KB |
Output is correct |
61 |
Correct |
524 ms |
34028 KB |
Output is correct |
62 |
Correct |
529 ms |
34156 KB |
Output is correct |
63 |
Correct |
535 ms |
34028 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
519 ms |
33240 KB |
Output is correct |
2 |
Correct |
517 ms |
33132 KB |
Output is correct |
3 |
Correct |
526 ms |
33260 KB |
Output is correct |
4 |
Correct |
521 ms |
33132 KB |
Output is correct |
5 |
Correct |
526 ms |
33004 KB |
Output is correct |
6 |
Correct |
524 ms |
33132 KB |
Output is correct |
7 |
Correct |
524 ms |
33200 KB |
Output is correct |
8 |
Correct |
523 ms |
33140 KB |
Output is correct |
9 |
Correct |
521 ms |
33132 KB |
Output is correct |
10 |
Correct |
519 ms |
33004 KB |
Output is correct |
11 |
Correct |
524 ms |
33260 KB |
Output is correct |
12 |
Correct |
537 ms |
33004 KB |
Output is correct |
13 |
Correct |
523 ms |
33132 KB |
Output is correct |
14 |
Correct |
516 ms |
33132 KB |
Output is correct |
15 |
Correct |
522 ms |
33132 KB |
Output is correct |
16 |
Correct |
527 ms |
33260 KB |
Output is correct |
17 |
Correct |
522 ms |
33004 KB |
Output is correct |
18 |
Correct |
522 ms |
33132 KB |
Output is correct |
19 |
Correct |
527 ms |
33132 KB |
Output is correct |
20 |
Correct |
523 ms |
33004 KB |
Output is correct |
21 |
Correct |
521 ms |
33004 KB |
Output is correct |
22 |
Correct |
532 ms |
33816 KB |
Output is correct |
23 |
Correct |
533 ms |
33900 KB |
Output is correct |
24 |
Correct |
528 ms |
33772 KB |
Output is correct |
25 |
Correct |
530 ms |
33888 KB |
Output is correct |
26 |
Correct |
527 ms |
33772 KB |
Output is correct |
27 |
Correct |
523 ms |
33900 KB |
Output is correct |
28 |
Correct |
525 ms |
33736 KB |
Output is correct |
29 |
Correct |
519 ms |
33772 KB |
Output is correct |
30 |
Correct |
525 ms |
33836 KB |
Output is correct |
31 |
Correct |
530 ms |
33772 KB |
Output is correct |
32 |
Correct |
524 ms |
34028 KB |
Output is correct |
33 |
Correct |
527 ms |
33684 KB |
Output is correct |
34 |
Correct |
534 ms |
33708 KB |
Output is correct |
35 |
Correct |
528 ms |
33772 KB |
Output is correct |
36 |
Correct |
532 ms |
33748 KB |
Output is correct |
37 |
Correct |
535 ms |
33900 KB |
Output is correct |
38 |
Correct |
525 ms |
33900 KB |
Output is correct |
39 |
Correct |
524 ms |
33860 KB |
Output is correct |
40 |
Correct |
530 ms |
33704 KB |
Output is correct |
41 |
Correct |
528 ms |
33772 KB |
Output is correct |
42 |
Correct |
523 ms |
33900 KB |
Output is correct |
43 |
Correct |
528 ms |
34156 KB |
Output is correct |
44 |
Correct |
526 ms |
34156 KB |
Output is correct |
45 |
Correct |
530 ms |
34028 KB |
Output is correct |
46 |
Correct |
523 ms |
34204 KB |
Output is correct |
47 |
Correct |
529 ms |
34176 KB |
Output is correct |
48 |
Correct |
529 ms |
34028 KB |
Output is correct |
49 |
Correct |
527 ms |
34156 KB |
Output is correct |
50 |
Correct |
533 ms |
34284 KB |
Output is correct |
51 |
Correct |
526 ms |
34028 KB |
Output is correct |
52 |
Correct |
533 ms |
34284 KB |
Output is correct |
53 |
Correct |
530 ms |
34156 KB |
Output is correct |
54 |
Correct |
528 ms |
34028 KB |
Output is correct |
55 |
Correct |
538 ms |
34372 KB |
Output is correct |
56 |
Correct |
533 ms |
34156 KB |
Output is correct |
57 |
Correct |
536 ms |
34160 KB |
Output is correct |
58 |
Correct |
533 ms |
34028 KB |
Output is correct |
59 |
Correct |
529 ms |
34232 KB |
Output is correct |
60 |
Correct |
534 ms |
34156 KB |
Output is correct |
61 |
Correct |
524 ms |
34028 KB |
Output is correct |
62 |
Correct |
529 ms |
34156 KB |
Output is correct |
63 |
Correct |
535 ms |
34028 KB |
Output is correct |
64 |
Correct |
578 ms |
35180 KB |
Output is correct |
65 |
Correct |
567 ms |
35308 KB |
Output is correct |
66 |
Correct |
575 ms |
35252 KB |
Output is correct |
67 |
Correct |
572 ms |
35180 KB |
Output is correct |
68 |
Correct |
564 ms |
35052 KB |
Output is correct |
69 |
Correct |
586 ms |
35084 KB |
Output is correct |
70 |
Correct |
570 ms |
35168 KB |
Output is correct |
71 |
Correct |
569 ms |
35180 KB |
Output is correct |
72 |
Correct |
567 ms |
35180 KB |
Output is correct |
73 |
Correct |
575 ms |
35256 KB |
Output is correct |
74 |
Correct |
568 ms |
35180 KB |
Output is correct |
75 |
Correct |
564 ms |
35092 KB |
Output is correct |
76 |
Correct |
568 ms |
35080 KB |
Output is correct |
77 |
Correct |
566 ms |
35308 KB |
Output is correct |
78 |
Correct |
572 ms |
35180 KB |
Output is correct |
79 |
Correct |
570 ms |
35180 KB |
Output is correct |
80 |
Correct |
563 ms |
35156 KB |
Output is correct |
81 |
Correct |
570 ms |
35180 KB |
Output is correct |
82 |
Correct |
567 ms |
35180 KB |
Output is correct |
83 |
Correct |
571 ms |
35180 KB |
Output is correct |
84 |
Correct |
583 ms |
35052 KB |
Output is correct |