#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#pragma GCC target("avx,avx2,fma")
#define MX 62
typedef long long ll;
using namespace std;
const int MOD = 998244353;
int cnt[101][101][101];
int a[8], b[12] = {0, 1, 2, 3, 0, 1, 2, 3, 4, 5, 6, 7}, c[12] = {1, 2, 3, 0, 4, 5, 6, 7, 5, 6, 7, 4};
int mp[505], val[11][101][101][101];
inline bool chk(string &s){
int n = s.size();
for (int i=0;i<n;i++){
int j = n-1-i;
if (i>j) break;
if (s[i]!=s[j]) return 0;
}
return 1;
}
int main(){
cin.tie(NULL);
ios_base::sync_with_stdio(false);
int n;
cin >> n;
unordered_set<string> st[11];
for (int i='a';i<='z';i++){
mp[i] = i-'a';
}
for (int i='A';i<='Z';i++){
mp[i] = i-'A'+26;
}
for (int i='0';i<='9';i++){
mp[i] = i-'0'+52;
}
for (int i=0;i<n;i++){
string s;
cin >> s;
int idx1 = mp[s[0]], idx2 = mp[s.back()], len = s.size();
cnt[len][idx1][idx2]++;
cnt[len][idx2][idx1]++;
if (st[len].find(s)!=st[len].end()){
cnt[len][idx1][idx2]--;
cnt[len][idx2][idx1]--;
continue;
}
reverse(s.begin(), s.end());
if (st[len].find(s)!=st[len].end()){
cnt[len][idx1][idx2]--;
cnt[len][idx2][idx1]--;
continue;
}
if (chk(s)) cnt[(int)s.size()][idx2][idx1]--;
st[len].insert(s);
}
for (register int len=3;len<=10;len++){
for (register int i=0;i<MX;i++){
for (register int j=0;j<MX;j++){
for (register int k=0;k<MX;k++){
for (register int l=0;l<MX;l++){
ll tmp = (ll)cnt[len][i][l] * cnt[len][j][l];
if (tmp>=MOD) tmp %= MOD;
tmp *= cnt[len][k][l];
if (tmp>=MOD) tmp %= MOD;
val[len][i][j][k] += tmp;
if (val[len][i][j][k]>=MOD) val[len][i][j][k] -= MOD;
}
}
}
}
}
int ans = 0;
for (register int len=3;len<=10;len++){
for (register int i=0;i<MX;i++){
for (register int j=0;j<MX;j++){
for (register int k=0;k<MX;k++) if (val[len][i][j][k]){
for (register int l=0;l<MX;l++) {
ll tmp = val[len][i][j][k];
tmp *= val[len][i][j][l];
if (tmp>=MOD) tmp %= MOD;
tmp *= val[len][i][k][l];
if (tmp>=MOD) tmp %= MOD;
tmp *= val[len][j][k][l];
if (tmp>=MOD) tmp %= MOD;
ans += tmp;
if (ans>=MOD) ans -= MOD;
}
}
}
}
}
printf("%d\n", ans);
return 0;
}
Compilation message
cubeword.cpp: In function 'int main()':
cubeword.cpp:42:27: warning: array subscript has type 'char' [-Wchar-subscripts]
42 | int idx1 = mp[s[0]], idx2 = mp[s.back()], len = s.size();
| ^
cubeword.cpp:42:46: warning: array subscript has type 'char' [-Wchar-subscripts]
42 | int idx1 = mp[s[0]], idx2 = mp[s.back()], len = s.size();
| ~~~~~~^~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
404 ms |
21188 KB |
Output is correct |
2 |
Correct |
436 ms |
21204 KB |
Output is correct |
3 |
Correct |
413 ms |
21060 KB |
Output is correct |
4 |
Correct |
392 ms |
21096 KB |
Output is correct |
5 |
Correct |
402 ms |
21112 KB |
Output is correct |
6 |
Correct |
442 ms |
21060 KB |
Output is correct |
7 |
Correct |
387 ms |
21128 KB |
Output is correct |
8 |
Correct |
425 ms |
21256 KB |
Output is correct |
9 |
Correct |
393 ms |
21060 KB |
Output is correct |
10 |
Correct |
403 ms |
21060 KB |
Output is correct |
11 |
Correct |
419 ms |
21048 KB |
Output is correct |
12 |
Correct |
440 ms |
21060 KB |
Output is correct |
13 |
Correct |
392 ms |
21128 KB |
Output is correct |
14 |
Correct |
423 ms |
21060 KB |
Output is correct |
15 |
Correct |
398 ms |
21140 KB |
Output is correct |
16 |
Correct |
424 ms |
21024 KB |
Output is correct |
17 |
Correct |
398 ms |
21140 KB |
Output is correct |
18 |
Correct |
423 ms |
21084 KB |
Output is correct |
19 |
Correct |
417 ms |
21112 KB |
Output is correct |
20 |
Correct |
417 ms |
21140 KB |
Output is correct |
21 |
Correct |
414 ms |
21208 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
404 ms |
21188 KB |
Output is correct |
2 |
Correct |
436 ms |
21204 KB |
Output is correct |
3 |
Correct |
413 ms |
21060 KB |
Output is correct |
4 |
Correct |
392 ms |
21096 KB |
Output is correct |
5 |
Correct |
402 ms |
21112 KB |
Output is correct |
6 |
Correct |
442 ms |
21060 KB |
Output is correct |
7 |
Correct |
387 ms |
21128 KB |
Output is correct |
8 |
Correct |
425 ms |
21256 KB |
Output is correct |
9 |
Correct |
393 ms |
21060 KB |
Output is correct |
10 |
Correct |
403 ms |
21060 KB |
Output is correct |
11 |
Correct |
419 ms |
21048 KB |
Output is correct |
12 |
Correct |
440 ms |
21060 KB |
Output is correct |
13 |
Correct |
392 ms |
21128 KB |
Output is correct |
14 |
Correct |
423 ms |
21060 KB |
Output is correct |
15 |
Correct |
398 ms |
21140 KB |
Output is correct |
16 |
Correct |
424 ms |
21024 KB |
Output is correct |
17 |
Correct |
398 ms |
21140 KB |
Output is correct |
18 |
Correct |
423 ms |
21084 KB |
Output is correct |
19 |
Correct |
417 ms |
21112 KB |
Output is correct |
20 |
Correct |
417 ms |
21140 KB |
Output is correct |
21 |
Correct |
414 ms |
21208 KB |
Output is correct |
22 |
Correct |
442 ms |
21660 KB |
Output is correct |
23 |
Correct |
408 ms |
21692 KB |
Output is correct |
24 |
Correct |
396 ms |
21700 KB |
Output is correct |
25 |
Correct |
425 ms |
21716 KB |
Output is correct |
26 |
Correct |
409 ms |
21700 KB |
Output is correct |
27 |
Correct |
411 ms |
21700 KB |
Output is correct |
28 |
Correct |
437 ms |
21740 KB |
Output is correct |
29 |
Correct |
418 ms |
21700 KB |
Output is correct |
30 |
Correct |
440 ms |
21640 KB |
Output is correct |
31 |
Correct |
401 ms |
21816 KB |
Output is correct |
32 |
Correct |
414 ms |
21720 KB |
Output is correct |
33 |
Correct |
442 ms |
21752 KB |
Output is correct |
34 |
Correct |
416 ms |
21696 KB |
Output is correct |
35 |
Correct |
408 ms |
21700 KB |
Output is correct |
36 |
Correct |
425 ms |
21672 KB |
Output is correct |
37 |
Correct |
417 ms |
21700 KB |
Output is correct |
38 |
Correct |
411 ms |
21884 KB |
Output is correct |
39 |
Correct |
401 ms |
21760 KB |
Output is correct |
40 |
Correct |
401 ms |
21816 KB |
Output is correct |
41 |
Correct |
405 ms |
21748 KB |
Output is correct |
42 |
Correct |
399 ms |
21740 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
404 ms |
21188 KB |
Output is correct |
2 |
Correct |
436 ms |
21204 KB |
Output is correct |
3 |
Correct |
413 ms |
21060 KB |
Output is correct |
4 |
Correct |
392 ms |
21096 KB |
Output is correct |
5 |
Correct |
402 ms |
21112 KB |
Output is correct |
6 |
Correct |
442 ms |
21060 KB |
Output is correct |
7 |
Correct |
387 ms |
21128 KB |
Output is correct |
8 |
Correct |
425 ms |
21256 KB |
Output is correct |
9 |
Correct |
393 ms |
21060 KB |
Output is correct |
10 |
Correct |
403 ms |
21060 KB |
Output is correct |
11 |
Correct |
419 ms |
21048 KB |
Output is correct |
12 |
Correct |
440 ms |
21060 KB |
Output is correct |
13 |
Correct |
392 ms |
21128 KB |
Output is correct |
14 |
Correct |
423 ms |
21060 KB |
Output is correct |
15 |
Correct |
398 ms |
21140 KB |
Output is correct |
16 |
Correct |
424 ms |
21024 KB |
Output is correct |
17 |
Correct |
398 ms |
21140 KB |
Output is correct |
18 |
Correct |
423 ms |
21084 KB |
Output is correct |
19 |
Correct |
417 ms |
21112 KB |
Output is correct |
20 |
Correct |
417 ms |
21140 KB |
Output is correct |
21 |
Correct |
414 ms |
21208 KB |
Output is correct |
22 |
Correct |
442 ms |
21660 KB |
Output is correct |
23 |
Correct |
408 ms |
21692 KB |
Output is correct |
24 |
Correct |
396 ms |
21700 KB |
Output is correct |
25 |
Correct |
425 ms |
21716 KB |
Output is correct |
26 |
Correct |
409 ms |
21700 KB |
Output is correct |
27 |
Correct |
411 ms |
21700 KB |
Output is correct |
28 |
Correct |
437 ms |
21740 KB |
Output is correct |
29 |
Correct |
418 ms |
21700 KB |
Output is correct |
30 |
Correct |
440 ms |
21640 KB |
Output is correct |
31 |
Correct |
401 ms |
21816 KB |
Output is correct |
32 |
Correct |
414 ms |
21720 KB |
Output is correct |
33 |
Correct |
442 ms |
21752 KB |
Output is correct |
34 |
Correct |
416 ms |
21696 KB |
Output is correct |
35 |
Correct |
408 ms |
21700 KB |
Output is correct |
36 |
Correct |
425 ms |
21672 KB |
Output is correct |
37 |
Correct |
417 ms |
21700 KB |
Output is correct |
38 |
Correct |
411 ms |
21884 KB |
Output is correct |
39 |
Correct |
401 ms |
21760 KB |
Output is correct |
40 |
Correct |
401 ms |
21816 KB |
Output is correct |
41 |
Correct |
405 ms |
21748 KB |
Output is correct |
42 |
Correct |
399 ms |
21740 KB |
Output is correct |
43 |
Correct |
500 ms |
21948 KB |
Output is correct |
44 |
Correct |
503 ms |
22064 KB |
Output is correct |
45 |
Correct |
492 ms |
21936 KB |
Output is correct |
46 |
Correct |
496 ms |
21960 KB |
Output is correct |
47 |
Correct |
488 ms |
22000 KB |
Output is correct |
48 |
Correct |
525 ms |
22084 KB |
Output is correct |
49 |
Correct |
501 ms |
21988 KB |
Output is correct |
50 |
Correct |
504 ms |
21960 KB |
Output is correct |
51 |
Correct |
497 ms |
21972 KB |
Output is correct |
52 |
Correct |
488 ms |
21952 KB |
Output is correct |
53 |
Correct |
488 ms |
21984 KB |
Output is correct |
54 |
Correct |
497 ms |
21904 KB |
Output is correct |
55 |
Correct |
511 ms |
21956 KB |
Output is correct |
56 |
Correct |
491 ms |
21896 KB |
Output is correct |
57 |
Correct |
497 ms |
21868 KB |
Output is correct |
58 |
Correct |
505 ms |
22004 KB |
Output is correct |
59 |
Correct |
506 ms |
21984 KB |
Output is correct |
60 |
Correct |
493 ms |
22080 KB |
Output is correct |
61 |
Correct |
501 ms |
21996 KB |
Output is correct |
62 |
Correct |
487 ms |
21916 KB |
Output is correct |
63 |
Correct |
497 ms |
22064 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
404 ms |
21188 KB |
Output is correct |
2 |
Correct |
436 ms |
21204 KB |
Output is correct |
3 |
Correct |
413 ms |
21060 KB |
Output is correct |
4 |
Correct |
392 ms |
21096 KB |
Output is correct |
5 |
Correct |
402 ms |
21112 KB |
Output is correct |
6 |
Correct |
442 ms |
21060 KB |
Output is correct |
7 |
Correct |
387 ms |
21128 KB |
Output is correct |
8 |
Correct |
425 ms |
21256 KB |
Output is correct |
9 |
Correct |
393 ms |
21060 KB |
Output is correct |
10 |
Correct |
403 ms |
21060 KB |
Output is correct |
11 |
Correct |
419 ms |
21048 KB |
Output is correct |
12 |
Correct |
440 ms |
21060 KB |
Output is correct |
13 |
Correct |
392 ms |
21128 KB |
Output is correct |
14 |
Correct |
423 ms |
21060 KB |
Output is correct |
15 |
Correct |
398 ms |
21140 KB |
Output is correct |
16 |
Correct |
424 ms |
21024 KB |
Output is correct |
17 |
Correct |
398 ms |
21140 KB |
Output is correct |
18 |
Correct |
423 ms |
21084 KB |
Output is correct |
19 |
Correct |
417 ms |
21112 KB |
Output is correct |
20 |
Correct |
417 ms |
21140 KB |
Output is correct |
21 |
Correct |
414 ms |
21208 KB |
Output is correct |
22 |
Correct |
442 ms |
21660 KB |
Output is correct |
23 |
Correct |
408 ms |
21692 KB |
Output is correct |
24 |
Correct |
396 ms |
21700 KB |
Output is correct |
25 |
Correct |
425 ms |
21716 KB |
Output is correct |
26 |
Correct |
409 ms |
21700 KB |
Output is correct |
27 |
Correct |
411 ms |
21700 KB |
Output is correct |
28 |
Correct |
437 ms |
21740 KB |
Output is correct |
29 |
Correct |
418 ms |
21700 KB |
Output is correct |
30 |
Correct |
440 ms |
21640 KB |
Output is correct |
31 |
Correct |
401 ms |
21816 KB |
Output is correct |
32 |
Correct |
414 ms |
21720 KB |
Output is correct |
33 |
Correct |
442 ms |
21752 KB |
Output is correct |
34 |
Correct |
416 ms |
21696 KB |
Output is correct |
35 |
Correct |
408 ms |
21700 KB |
Output is correct |
36 |
Correct |
425 ms |
21672 KB |
Output is correct |
37 |
Correct |
417 ms |
21700 KB |
Output is correct |
38 |
Correct |
411 ms |
21884 KB |
Output is correct |
39 |
Correct |
401 ms |
21760 KB |
Output is correct |
40 |
Correct |
401 ms |
21816 KB |
Output is correct |
41 |
Correct |
405 ms |
21748 KB |
Output is correct |
42 |
Correct |
399 ms |
21740 KB |
Output is correct |
43 |
Correct |
500 ms |
21948 KB |
Output is correct |
44 |
Correct |
503 ms |
22064 KB |
Output is correct |
45 |
Correct |
492 ms |
21936 KB |
Output is correct |
46 |
Correct |
496 ms |
21960 KB |
Output is correct |
47 |
Correct |
488 ms |
22000 KB |
Output is correct |
48 |
Correct |
525 ms |
22084 KB |
Output is correct |
49 |
Correct |
501 ms |
21988 KB |
Output is correct |
50 |
Correct |
504 ms |
21960 KB |
Output is correct |
51 |
Correct |
497 ms |
21972 KB |
Output is correct |
52 |
Correct |
488 ms |
21952 KB |
Output is correct |
53 |
Correct |
488 ms |
21984 KB |
Output is correct |
54 |
Correct |
497 ms |
21904 KB |
Output is correct |
55 |
Correct |
511 ms |
21956 KB |
Output is correct |
56 |
Correct |
491 ms |
21896 KB |
Output is correct |
57 |
Correct |
497 ms |
21868 KB |
Output is correct |
58 |
Correct |
505 ms |
22004 KB |
Output is correct |
59 |
Correct |
506 ms |
21984 KB |
Output is correct |
60 |
Correct |
493 ms |
22080 KB |
Output is correct |
61 |
Correct |
501 ms |
21996 KB |
Output is correct |
62 |
Correct |
487 ms |
21916 KB |
Output is correct |
63 |
Correct |
497 ms |
22064 KB |
Output is correct |
64 |
Correct |
1065 ms |
22228 KB |
Output is correct |
65 |
Correct |
1069 ms |
22216 KB |
Output is correct |
66 |
Correct |
1095 ms |
22276 KB |
Output is correct |
67 |
Correct |
1090 ms |
22224 KB |
Output is correct |
68 |
Correct |
1068 ms |
22336 KB |
Output is correct |
69 |
Correct |
1097 ms |
22432 KB |
Output is correct |
70 |
Correct |
1068 ms |
22360 KB |
Output is correct |
71 |
Correct |
1074 ms |
22388 KB |
Output is correct |
72 |
Correct |
1060 ms |
22224 KB |
Output is correct |
73 |
Correct |
1064 ms |
22260 KB |
Output is correct |
74 |
Correct |
1070 ms |
22212 KB |
Output is correct |
75 |
Correct |
1056 ms |
22216 KB |
Output is correct |
76 |
Correct |
1060 ms |
22328 KB |
Output is correct |
77 |
Correct |
1050 ms |
22220 KB |
Output is correct |
78 |
Correct |
1054 ms |
22304 KB |
Output is correct |
79 |
Correct |
1074 ms |
22132 KB |
Output is correct |
80 |
Correct |
1080 ms |
22980 KB |
Output is correct |
81 |
Correct |
1068 ms |
23032 KB |
Output is correct |
82 |
Correct |
1081 ms |
23012 KB |
Output is correct |
83 |
Correct |
1085 ms |
22956 KB |
Output is correct |
84 |
Correct |
1082 ms |
22968 KB |
Output is correct |