#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];
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;
if (!tmp) continue;
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++){
for (register int l=0;l<MX;l++){
ll tmp = val[len][i][j][k];
tmp = tmp*val[len][i][j][l];
if (tmp>=MOD) tmp %= MOD;
tmp = tmp*val[len][i][k][l];
if (tmp>=MOD) tmp %= MOD;
tmp = tmp*val[len][j][k][l];
if (tmp>=MOD) tmp %= MOD;
if (!tmp) continue;
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();
| ~~~~~~^~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
751 ms |
7396 KB |
Output is correct |
2 |
Correct |
735 ms |
7384 KB |
Output is correct |
3 |
Correct |
735 ms |
7364 KB |
Output is correct |
4 |
Correct |
767 ms |
7400 KB |
Output is correct |
5 |
Correct |
751 ms |
7480 KB |
Output is correct |
6 |
Correct |
731 ms |
7456 KB |
Output is correct |
7 |
Correct |
739 ms |
7304 KB |
Output is correct |
8 |
Correct |
825 ms |
7372 KB |
Output is correct |
9 |
Correct |
748 ms |
7328 KB |
Output is correct |
10 |
Correct |
735 ms |
7524 KB |
Output is correct |
11 |
Correct |
730 ms |
7396 KB |
Output is correct |
12 |
Correct |
744 ms |
7516 KB |
Output is correct |
13 |
Correct |
753 ms |
7520 KB |
Output is correct |
14 |
Correct |
754 ms |
7456 KB |
Output is correct |
15 |
Correct |
800 ms |
7388 KB |
Output is correct |
16 |
Correct |
734 ms |
7472 KB |
Output is correct |
17 |
Correct |
731 ms |
7416 KB |
Output is correct |
18 |
Correct |
768 ms |
7388 KB |
Output is correct |
19 |
Correct |
738 ms |
7608 KB |
Output is correct |
20 |
Correct |
733 ms |
7520 KB |
Output is correct |
21 |
Correct |
741 ms |
7536 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
751 ms |
7396 KB |
Output is correct |
2 |
Correct |
735 ms |
7384 KB |
Output is correct |
3 |
Correct |
735 ms |
7364 KB |
Output is correct |
4 |
Correct |
767 ms |
7400 KB |
Output is correct |
5 |
Correct |
751 ms |
7480 KB |
Output is correct |
6 |
Correct |
731 ms |
7456 KB |
Output is correct |
7 |
Correct |
739 ms |
7304 KB |
Output is correct |
8 |
Correct |
825 ms |
7372 KB |
Output is correct |
9 |
Correct |
748 ms |
7328 KB |
Output is correct |
10 |
Correct |
735 ms |
7524 KB |
Output is correct |
11 |
Correct |
730 ms |
7396 KB |
Output is correct |
12 |
Correct |
744 ms |
7516 KB |
Output is correct |
13 |
Correct |
753 ms |
7520 KB |
Output is correct |
14 |
Correct |
754 ms |
7456 KB |
Output is correct |
15 |
Correct |
800 ms |
7388 KB |
Output is correct |
16 |
Correct |
734 ms |
7472 KB |
Output is correct |
17 |
Correct |
731 ms |
7416 KB |
Output is correct |
18 |
Correct |
768 ms |
7388 KB |
Output is correct |
19 |
Correct |
738 ms |
7608 KB |
Output is correct |
20 |
Correct |
733 ms |
7520 KB |
Output is correct |
21 |
Correct |
741 ms |
7536 KB |
Output is correct |
22 |
Correct |
759 ms |
9016 KB |
Output is correct |
23 |
Correct |
796 ms |
9080 KB |
Output is correct |
24 |
Correct |
762 ms |
8972 KB |
Output is correct |
25 |
Correct |
761 ms |
8976 KB |
Output is correct |
26 |
Correct |
751 ms |
8976 KB |
Output is correct |
27 |
Correct |
737 ms |
8976 KB |
Output is correct |
28 |
Correct |
769 ms |
9020 KB |
Output is correct |
29 |
Correct |
753 ms |
8896 KB |
Output is correct |
30 |
Correct |
750 ms |
8980 KB |
Output is correct |
31 |
Correct |
753 ms |
8980 KB |
Output is correct |
32 |
Correct |
754 ms |
9028 KB |
Output is correct |
33 |
Correct |
757 ms |
8972 KB |
Output is correct |
34 |
Correct |
755 ms |
9004 KB |
Output is correct |
35 |
Correct |
742 ms |
8976 KB |
Output is correct |
36 |
Correct |
829 ms |
8980 KB |
Output is correct |
37 |
Correct |
777 ms |
8972 KB |
Output is correct |
38 |
Correct |
784 ms |
9080 KB |
Output is correct |
39 |
Correct |
753 ms |
8988 KB |
Output is correct |
40 |
Correct |
758 ms |
8960 KB |
Output is correct |
41 |
Correct |
783 ms |
9096 KB |
Output is correct |
42 |
Correct |
759 ms |
8968 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
751 ms |
7396 KB |
Output is correct |
2 |
Correct |
735 ms |
7384 KB |
Output is correct |
3 |
Correct |
735 ms |
7364 KB |
Output is correct |
4 |
Correct |
767 ms |
7400 KB |
Output is correct |
5 |
Correct |
751 ms |
7480 KB |
Output is correct |
6 |
Correct |
731 ms |
7456 KB |
Output is correct |
7 |
Correct |
739 ms |
7304 KB |
Output is correct |
8 |
Correct |
825 ms |
7372 KB |
Output is correct |
9 |
Correct |
748 ms |
7328 KB |
Output is correct |
10 |
Correct |
735 ms |
7524 KB |
Output is correct |
11 |
Correct |
730 ms |
7396 KB |
Output is correct |
12 |
Correct |
744 ms |
7516 KB |
Output is correct |
13 |
Correct |
753 ms |
7520 KB |
Output is correct |
14 |
Correct |
754 ms |
7456 KB |
Output is correct |
15 |
Correct |
800 ms |
7388 KB |
Output is correct |
16 |
Correct |
734 ms |
7472 KB |
Output is correct |
17 |
Correct |
731 ms |
7416 KB |
Output is correct |
18 |
Correct |
768 ms |
7388 KB |
Output is correct |
19 |
Correct |
738 ms |
7608 KB |
Output is correct |
20 |
Correct |
733 ms |
7520 KB |
Output is correct |
21 |
Correct |
741 ms |
7536 KB |
Output is correct |
22 |
Correct |
759 ms |
9016 KB |
Output is correct |
23 |
Correct |
796 ms |
9080 KB |
Output is correct |
24 |
Correct |
762 ms |
8972 KB |
Output is correct |
25 |
Correct |
761 ms |
8976 KB |
Output is correct |
26 |
Correct |
751 ms |
8976 KB |
Output is correct |
27 |
Correct |
737 ms |
8976 KB |
Output is correct |
28 |
Correct |
769 ms |
9020 KB |
Output is correct |
29 |
Correct |
753 ms |
8896 KB |
Output is correct |
30 |
Correct |
750 ms |
8980 KB |
Output is correct |
31 |
Correct |
753 ms |
8980 KB |
Output is correct |
32 |
Correct |
754 ms |
9028 KB |
Output is correct |
33 |
Correct |
757 ms |
8972 KB |
Output is correct |
34 |
Correct |
755 ms |
9004 KB |
Output is correct |
35 |
Correct |
742 ms |
8976 KB |
Output is correct |
36 |
Correct |
829 ms |
8980 KB |
Output is correct |
37 |
Correct |
777 ms |
8972 KB |
Output is correct |
38 |
Correct |
784 ms |
9080 KB |
Output is correct |
39 |
Correct |
753 ms |
8988 KB |
Output is correct |
40 |
Correct |
758 ms |
8960 KB |
Output is correct |
41 |
Correct |
783 ms |
9096 KB |
Output is correct |
42 |
Correct |
759 ms |
8968 KB |
Output is correct |
43 |
Correct |
805 ms |
13072 KB |
Output is correct |
44 |
Correct |
824 ms |
13140 KB |
Output is correct |
45 |
Correct |
859 ms |
13124 KB |
Output is correct |
46 |
Correct |
814 ms |
13060 KB |
Output is correct |
47 |
Correct |
809 ms |
13060 KB |
Output is correct |
48 |
Correct |
837 ms |
13220 KB |
Output is correct |
49 |
Correct |
811 ms |
13068 KB |
Output is correct |
50 |
Correct |
869 ms |
13060 KB |
Output is correct |
51 |
Correct |
812 ms |
13104 KB |
Output is correct |
52 |
Correct |
815 ms |
13120 KB |
Output is correct |
53 |
Correct |
802 ms |
13148 KB |
Output is correct |
54 |
Correct |
823 ms |
13140 KB |
Output is correct |
55 |
Correct |
810 ms |
13064 KB |
Output is correct |
56 |
Correct |
822 ms |
13112 KB |
Output is correct |
57 |
Correct |
830 ms |
13152 KB |
Output is correct |
58 |
Correct |
796 ms |
13040 KB |
Output is correct |
59 |
Correct |
816 ms |
13060 KB |
Output is correct |
60 |
Correct |
803 ms |
13064 KB |
Output is correct |
61 |
Correct |
804 ms |
13060 KB |
Output is correct |
62 |
Correct |
806 ms |
13124 KB |
Output is correct |
63 |
Correct |
810 ms |
13060 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
751 ms |
7396 KB |
Output is correct |
2 |
Correct |
735 ms |
7384 KB |
Output is correct |
3 |
Correct |
735 ms |
7364 KB |
Output is correct |
4 |
Correct |
767 ms |
7400 KB |
Output is correct |
5 |
Correct |
751 ms |
7480 KB |
Output is correct |
6 |
Correct |
731 ms |
7456 KB |
Output is correct |
7 |
Correct |
739 ms |
7304 KB |
Output is correct |
8 |
Correct |
825 ms |
7372 KB |
Output is correct |
9 |
Correct |
748 ms |
7328 KB |
Output is correct |
10 |
Correct |
735 ms |
7524 KB |
Output is correct |
11 |
Correct |
730 ms |
7396 KB |
Output is correct |
12 |
Correct |
744 ms |
7516 KB |
Output is correct |
13 |
Correct |
753 ms |
7520 KB |
Output is correct |
14 |
Correct |
754 ms |
7456 KB |
Output is correct |
15 |
Correct |
800 ms |
7388 KB |
Output is correct |
16 |
Correct |
734 ms |
7472 KB |
Output is correct |
17 |
Correct |
731 ms |
7416 KB |
Output is correct |
18 |
Correct |
768 ms |
7388 KB |
Output is correct |
19 |
Correct |
738 ms |
7608 KB |
Output is correct |
20 |
Correct |
733 ms |
7520 KB |
Output is correct |
21 |
Correct |
741 ms |
7536 KB |
Output is correct |
22 |
Correct |
759 ms |
9016 KB |
Output is correct |
23 |
Correct |
796 ms |
9080 KB |
Output is correct |
24 |
Correct |
762 ms |
8972 KB |
Output is correct |
25 |
Correct |
761 ms |
8976 KB |
Output is correct |
26 |
Correct |
751 ms |
8976 KB |
Output is correct |
27 |
Correct |
737 ms |
8976 KB |
Output is correct |
28 |
Correct |
769 ms |
9020 KB |
Output is correct |
29 |
Correct |
753 ms |
8896 KB |
Output is correct |
30 |
Correct |
750 ms |
8980 KB |
Output is correct |
31 |
Correct |
753 ms |
8980 KB |
Output is correct |
32 |
Correct |
754 ms |
9028 KB |
Output is correct |
33 |
Correct |
757 ms |
8972 KB |
Output is correct |
34 |
Correct |
755 ms |
9004 KB |
Output is correct |
35 |
Correct |
742 ms |
8976 KB |
Output is correct |
36 |
Correct |
829 ms |
8980 KB |
Output is correct |
37 |
Correct |
777 ms |
8972 KB |
Output is correct |
38 |
Correct |
784 ms |
9080 KB |
Output is correct |
39 |
Correct |
753 ms |
8988 KB |
Output is correct |
40 |
Correct |
758 ms |
8960 KB |
Output is correct |
41 |
Correct |
783 ms |
9096 KB |
Output is correct |
42 |
Correct |
759 ms |
8968 KB |
Output is correct |
43 |
Correct |
805 ms |
13072 KB |
Output is correct |
44 |
Correct |
824 ms |
13140 KB |
Output is correct |
45 |
Correct |
859 ms |
13124 KB |
Output is correct |
46 |
Correct |
814 ms |
13060 KB |
Output is correct |
47 |
Correct |
809 ms |
13060 KB |
Output is correct |
48 |
Correct |
837 ms |
13220 KB |
Output is correct |
49 |
Correct |
811 ms |
13068 KB |
Output is correct |
50 |
Correct |
869 ms |
13060 KB |
Output is correct |
51 |
Correct |
812 ms |
13104 KB |
Output is correct |
52 |
Correct |
815 ms |
13120 KB |
Output is correct |
53 |
Correct |
802 ms |
13148 KB |
Output is correct |
54 |
Correct |
823 ms |
13140 KB |
Output is correct |
55 |
Correct |
810 ms |
13064 KB |
Output is correct |
56 |
Correct |
822 ms |
13112 KB |
Output is correct |
57 |
Correct |
830 ms |
13152 KB |
Output is correct |
58 |
Correct |
796 ms |
13040 KB |
Output is correct |
59 |
Correct |
816 ms |
13060 KB |
Output is correct |
60 |
Correct |
803 ms |
13064 KB |
Output is correct |
61 |
Correct |
804 ms |
13060 KB |
Output is correct |
62 |
Correct |
806 ms |
13124 KB |
Output is correct |
63 |
Correct |
810 ms |
13060 KB |
Output is correct |
64 |
Execution timed out |
1198 ms |
22160 KB |
Time limit exceeded |
65 |
Halted |
0 ms |
0 KB |
- |