#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++) if (val[len][i][j][l] && val[len][i][k][l] && val[len][j][k][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();
| ~~~~~~^~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
362 ms |
21112 KB |
Output is correct |
2 |
Correct |
360 ms |
21124 KB |
Output is correct |
3 |
Correct |
380 ms |
21112 KB |
Output is correct |
4 |
Correct |
359 ms |
21092 KB |
Output is correct |
5 |
Correct |
360 ms |
21144 KB |
Output is correct |
6 |
Correct |
350 ms |
21044 KB |
Output is correct |
7 |
Correct |
353 ms |
21112 KB |
Output is correct |
8 |
Correct |
356 ms |
21060 KB |
Output is correct |
9 |
Correct |
355 ms |
21060 KB |
Output is correct |
10 |
Correct |
356 ms |
21148 KB |
Output is correct |
11 |
Correct |
361 ms |
21116 KB |
Output is correct |
12 |
Correct |
364 ms |
21084 KB |
Output is correct |
13 |
Correct |
362 ms |
21188 KB |
Output is correct |
14 |
Correct |
361 ms |
21040 KB |
Output is correct |
15 |
Correct |
362 ms |
21092 KB |
Output is correct |
16 |
Correct |
352 ms |
21128 KB |
Output is correct |
17 |
Correct |
360 ms |
21060 KB |
Output is correct |
18 |
Correct |
374 ms |
21116 KB |
Output is correct |
19 |
Correct |
354 ms |
21112 KB |
Output is correct |
20 |
Correct |
362 ms |
21112 KB |
Output is correct |
21 |
Correct |
364 ms |
21056 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
362 ms |
21112 KB |
Output is correct |
2 |
Correct |
360 ms |
21124 KB |
Output is correct |
3 |
Correct |
380 ms |
21112 KB |
Output is correct |
4 |
Correct |
359 ms |
21092 KB |
Output is correct |
5 |
Correct |
360 ms |
21144 KB |
Output is correct |
6 |
Correct |
350 ms |
21044 KB |
Output is correct |
7 |
Correct |
353 ms |
21112 KB |
Output is correct |
8 |
Correct |
356 ms |
21060 KB |
Output is correct |
9 |
Correct |
355 ms |
21060 KB |
Output is correct |
10 |
Correct |
356 ms |
21148 KB |
Output is correct |
11 |
Correct |
361 ms |
21116 KB |
Output is correct |
12 |
Correct |
364 ms |
21084 KB |
Output is correct |
13 |
Correct |
362 ms |
21188 KB |
Output is correct |
14 |
Correct |
361 ms |
21040 KB |
Output is correct |
15 |
Correct |
362 ms |
21092 KB |
Output is correct |
16 |
Correct |
352 ms |
21128 KB |
Output is correct |
17 |
Correct |
360 ms |
21060 KB |
Output is correct |
18 |
Correct |
374 ms |
21116 KB |
Output is correct |
19 |
Correct |
354 ms |
21112 KB |
Output is correct |
20 |
Correct |
362 ms |
21112 KB |
Output is correct |
21 |
Correct |
364 ms |
21056 KB |
Output is correct |
22 |
Correct |
369 ms |
21660 KB |
Output is correct |
23 |
Correct |
368 ms |
21732 KB |
Output is correct |
24 |
Correct |
359 ms |
21664 KB |
Output is correct |
25 |
Correct |
370 ms |
21836 KB |
Output is correct |
26 |
Correct |
368 ms |
21732 KB |
Output is correct |
27 |
Correct |
362 ms |
21704 KB |
Output is correct |
28 |
Correct |
381 ms |
21700 KB |
Output is correct |
29 |
Correct |
361 ms |
21720 KB |
Output is correct |
30 |
Correct |
389 ms |
21740 KB |
Output is correct |
31 |
Correct |
399 ms |
21640 KB |
Output is correct |
32 |
Correct |
410 ms |
21700 KB |
Output is correct |
33 |
Correct |
383 ms |
21688 KB |
Output is correct |
34 |
Correct |
380 ms |
21692 KB |
Output is correct |
35 |
Correct |
379 ms |
21716 KB |
Output is correct |
36 |
Correct |
362 ms |
21732 KB |
Output is correct |
37 |
Correct |
372 ms |
21748 KB |
Output is correct |
38 |
Correct |
360 ms |
21648 KB |
Output is correct |
39 |
Correct |
363 ms |
21652 KB |
Output is correct |
40 |
Correct |
395 ms |
21776 KB |
Output is correct |
41 |
Correct |
372 ms |
21700 KB |
Output is correct |
42 |
Correct |
373 ms |
21756 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
362 ms |
21112 KB |
Output is correct |
2 |
Correct |
360 ms |
21124 KB |
Output is correct |
3 |
Correct |
380 ms |
21112 KB |
Output is correct |
4 |
Correct |
359 ms |
21092 KB |
Output is correct |
5 |
Correct |
360 ms |
21144 KB |
Output is correct |
6 |
Correct |
350 ms |
21044 KB |
Output is correct |
7 |
Correct |
353 ms |
21112 KB |
Output is correct |
8 |
Correct |
356 ms |
21060 KB |
Output is correct |
9 |
Correct |
355 ms |
21060 KB |
Output is correct |
10 |
Correct |
356 ms |
21148 KB |
Output is correct |
11 |
Correct |
361 ms |
21116 KB |
Output is correct |
12 |
Correct |
364 ms |
21084 KB |
Output is correct |
13 |
Correct |
362 ms |
21188 KB |
Output is correct |
14 |
Correct |
361 ms |
21040 KB |
Output is correct |
15 |
Correct |
362 ms |
21092 KB |
Output is correct |
16 |
Correct |
352 ms |
21128 KB |
Output is correct |
17 |
Correct |
360 ms |
21060 KB |
Output is correct |
18 |
Correct |
374 ms |
21116 KB |
Output is correct |
19 |
Correct |
354 ms |
21112 KB |
Output is correct |
20 |
Correct |
362 ms |
21112 KB |
Output is correct |
21 |
Correct |
364 ms |
21056 KB |
Output is correct |
22 |
Correct |
369 ms |
21660 KB |
Output is correct |
23 |
Correct |
368 ms |
21732 KB |
Output is correct |
24 |
Correct |
359 ms |
21664 KB |
Output is correct |
25 |
Correct |
370 ms |
21836 KB |
Output is correct |
26 |
Correct |
368 ms |
21732 KB |
Output is correct |
27 |
Correct |
362 ms |
21704 KB |
Output is correct |
28 |
Correct |
381 ms |
21700 KB |
Output is correct |
29 |
Correct |
361 ms |
21720 KB |
Output is correct |
30 |
Correct |
389 ms |
21740 KB |
Output is correct |
31 |
Correct |
399 ms |
21640 KB |
Output is correct |
32 |
Correct |
410 ms |
21700 KB |
Output is correct |
33 |
Correct |
383 ms |
21688 KB |
Output is correct |
34 |
Correct |
380 ms |
21692 KB |
Output is correct |
35 |
Correct |
379 ms |
21716 KB |
Output is correct |
36 |
Correct |
362 ms |
21732 KB |
Output is correct |
37 |
Correct |
372 ms |
21748 KB |
Output is correct |
38 |
Correct |
360 ms |
21648 KB |
Output is correct |
39 |
Correct |
363 ms |
21652 KB |
Output is correct |
40 |
Correct |
395 ms |
21776 KB |
Output is correct |
41 |
Correct |
372 ms |
21700 KB |
Output is correct |
42 |
Correct |
373 ms |
21756 KB |
Output is correct |
43 |
Correct |
462 ms |
21960 KB |
Output is correct |
44 |
Correct |
456 ms |
21892 KB |
Output is correct |
45 |
Correct |
462 ms |
22184 KB |
Output is correct |
46 |
Correct |
459 ms |
21980 KB |
Output is correct |
47 |
Correct |
459 ms |
21980 KB |
Output is correct |
48 |
Correct |
457 ms |
21988 KB |
Output is correct |
49 |
Correct |
458 ms |
21980 KB |
Output is correct |
50 |
Correct |
453 ms |
22108 KB |
Output is correct |
51 |
Correct |
453 ms |
21944 KB |
Output is correct |
52 |
Correct |
461 ms |
21940 KB |
Output is correct |
53 |
Correct |
452 ms |
22072 KB |
Output is correct |
54 |
Correct |
464 ms |
21928 KB |
Output is correct |
55 |
Correct |
481 ms |
21976 KB |
Output is correct |
56 |
Correct |
452 ms |
21956 KB |
Output is correct |
57 |
Correct |
448 ms |
21960 KB |
Output is correct |
58 |
Correct |
450 ms |
22096 KB |
Output is correct |
59 |
Correct |
458 ms |
22028 KB |
Output is correct |
60 |
Correct |
455 ms |
21956 KB |
Output is correct |
61 |
Correct |
452 ms |
21900 KB |
Output is correct |
62 |
Correct |
458 ms |
21976 KB |
Output is correct |
63 |
Correct |
473 ms |
21980 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
362 ms |
21112 KB |
Output is correct |
2 |
Correct |
360 ms |
21124 KB |
Output is correct |
3 |
Correct |
380 ms |
21112 KB |
Output is correct |
4 |
Correct |
359 ms |
21092 KB |
Output is correct |
5 |
Correct |
360 ms |
21144 KB |
Output is correct |
6 |
Correct |
350 ms |
21044 KB |
Output is correct |
7 |
Correct |
353 ms |
21112 KB |
Output is correct |
8 |
Correct |
356 ms |
21060 KB |
Output is correct |
9 |
Correct |
355 ms |
21060 KB |
Output is correct |
10 |
Correct |
356 ms |
21148 KB |
Output is correct |
11 |
Correct |
361 ms |
21116 KB |
Output is correct |
12 |
Correct |
364 ms |
21084 KB |
Output is correct |
13 |
Correct |
362 ms |
21188 KB |
Output is correct |
14 |
Correct |
361 ms |
21040 KB |
Output is correct |
15 |
Correct |
362 ms |
21092 KB |
Output is correct |
16 |
Correct |
352 ms |
21128 KB |
Output is correct |
17 |
Correct |
360 ms |
21060 KB |
Output is correct |
18 |
Correct |
374 ms |
21116 KB |
Output is correct |
19 |
Correct |
354 ms |
21112 KB |
Output is correct |
20 |
Correct |
362 ms |
21112 KB |
Output is correct |
21 |
Correct |
364 ms |
21056 KB |
Output is correct |
22 |
Correct |
369 ms |
21660 KB |
Output is correct |
23 |
Correct |
368 ms |
21732 KB |
Output is correct |
24 |
Correct |
359 ms |
21664 KB |
Output is correct |
25 |
Correct |
370 ms |
21836 KB |
Output is correct |
26 |
Correct |
368 ms |
21732 KB |
Output is correct |
27 |
Correct |
362 ms |
21704 KB |
Output is correct |
28 |
Correct |
381 ms |
21700 KB |
Output is correct |
29 |
Correct |
361 ms |
21720 KB |
Output is correct |
30 |
Correct |
389 ms |
21740 KB |
Output is correct |
31 |
Correct |
399 ms |
21640 KB |
Output is correct |
32 |
Correct |
410 ms |
21700 KB |
Output is correct |
33 |
Correct |
383 ms |
21688 KB |
Output is correct |
34 |
Correct |
380 ms |
21692 KB |
Output is correct |
35 |
Correct |
379 ms |
21716 KB |
Output is correct |
36 |
Correct |
362 ms |
21732 KB |
Output is correct |
37 |
Correct |
372 ms |
21748 KB |
Output is correct |
38 |
Correct |
360 ms |
21648 KB |
Output is correct |
39 |
Correct |
363 ms |
21652 KB |
Output is correct |
40 |
Correct |
395 ms |
21776 KB |
Output is correct |
41 |
Correct |
372 ms |
21700 KB |
Output is correct |
42 |
Correct |
373 ms |
21756 KB |
Output is correct |
43 |
Correct |
462 ms |
21960 KB |
Output is correct |
44 |
Correct |
456 ms |
21892 KB |
Output is correct |
45 |
Correct |
462 ms |
22184 KB |
Output is correct |
46 |
Correct |
459 ms |
21980 KB |
Output is correct |
47 |
Correct |
459 ms |
21980 KB |
Output is correct |
48 |
Correct |
457 ms |
21988 KB |
Output is correct |
49 |
Correct |
458 ms |
21980 KB |
Output is correct |
50 |
Correct |
453 ms |
22108 KB |
Output is correct |
51 |
Correct |
453 ms |
21944 KB |
Output is correct |
52 |
Correct |
461 ms |
21940 KB |
Output is correct |
53 |
Correct |
452 ms |
22072 KB |
Output is correct |
54 |
Correct |
464 ms |
21928 KB |
Output is correct |
55 |
Correct |
481 ms |
21976 KB |
Output is correct |
56 |
Correct |
452 ms |
21956 KB |
Output is correct |
57 |
Correct |
448 ms |
21960 KB |
Output is correct |
58 |
Correct |
450 ms |
22096 KB |
Output is correct |
59 |
Correct |
458 ms |
22028 KB |
Output is correct |
60 |
Correct |
455 ms |
21956 KB |
Output is correct |
61 |
Correct |
452 ms |
21900 KB |
Output is correct |
62 |
Correct |
458 ms |
21976 KB |
Output is correct |
63 |
Correct |
473 ms |
21980 KB |
Output is correct |
64 |
Execution timed out |
1172 ms |
22232 KB |
Time limit exceeded |
65 |
Halted |
0 ms |
0 KB |
- |