#include <bits/stdc++.h>
#define debug(x) cerr << #x << " " << x << "\n"
#define debugs(x) cerr << #x << " " << x << " "
#pragma GCC optimize("Ofast")
using namespace std;
typedef long long ll;
typedef pair <ll, ll> pii;
const ll NMAX = 200002;
const ll INF = (1LL << 58);
const ll nrbits = 20;
const ll MOD = 998244353;
vector <pii> lung[11];
const int VMAX = 63;
int cod(char c){
if('a' <= c && c <= 'z')
return c - 'a';
if('A' <= c && c <= 'Z')
return (c - 'A') + 26;
if('0' <= c && c <= '9')
return (c - '0') + 52;
}
int c[VMAX][VMAX];
int dp[VMAX][VMAX][VMAX];
void add(int &x, int val){
x += val;
if(x >= MOD)
x -= MOD;
if(x < 0)
x += MOD;
}
map <string, int> mp;
int main() {
#ifdef HOME
ifstream cin(".in");
ofstream cout(".out");
#endif // HOME
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int n, i;
cin >> n;
for(i = 1; i <= n; i++){
string s;
cin >> s;
mp[s]++;
if(mp[s] == 1)
lung[s.size()].push_back({cod(s[0]), cod(s.back())});
string a= s;
reverse(a.begin(), a.end());
mp[a]++;
if(mp[a] == 1)
lung[s.size()].push_back({cod(s.back()), cod(s[0])});
}
int sol = 0;
for(int i = 1; i <= 10; i++){
if(!lung[i].size()) continue;
for(int j = 0; j < VMAX; j++) for(int t = 0; t < VMAX; t++) c[j][t] = 0;
for(auto x : lung[i]){
c[x.first][x.second]++;
}
for(int j = 0; j < VMAX; j++){
for(int t = j; t < VMAX; t++){
for(int k = t; k < VMAX; k++){
dp[j][t][k] = 0;
for(int aici = 0; aici < VMAX; aici++){
add(dp[j][t][k], (1LL * c[aici][j] * c[aici][t]) % MOD * c[aici][k] % MOD);
}
/// aici se pune
dp[j][k][t] = dp[t][j][k] = dp[t][k][j] = dp[k][j][t] = dp[k][t][j] = dp[j][t][k];
}
}
}
for(int a = 0; a < VMAX; a++){
for(int b = a; b < VMAX; b++){
for(int c = b; c < VMAX; c++){
for(int d = c; d < VMAX; d++){
int perm = 24;
if(a == b)
perm /= 2;
if(a == c)
perm /= 3;
if(a == d)
perm /= 4;
if(a != b && b == c){
perm /= 2;
}
if(a != b && b == d){
perm /= 3;
}
if(b != c && c == d){
perm /= 2;
}
add(sol, (1LL * dp[a][b][c] * dp[a][b][d]) % MOD * dp[b][c][d] % MOD * dp[a][c][d] % MOD * perm % MOD);
}
}
}
}
}
cout << sol << "\n";
return 0;
}
Compilation message
cubeword.cpp: In function 'int cod(char)':
cubeword.cpp:26:1: warning: control reaches end of non-void function [-Wreturn-type]
26 | }
| ^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
261 ms |
18860 KB |
Output is correct |
2 |
Correct |
276 ms |
18716 KB |
Output is correct |
3 |
Correct |
266 ms |
18860 KB |
Output is correct |
4 |
Correct |
313 ms |
18580 KB |
Output is correct |
5 |
Correct |
267 ms |
18856 KB |
Output is correct |
6 |
Correct |
272 ms |
18804 KB |
Output is correct |
7 |
Correct |
263 ms |
18716 KB |
Output is correct |
8 |
Correct |
284 ms |
18868 KB |
Output is correct |
9 |
Correct |
293 ms |
18844 KB |
Output is correct |
10 |
Correct |
264 ms |
18780 KB |
Output is correct |
11 |
Correct |
279 ms |
19032 KB |
Output is correct |
12 |
Correct |
288 ms |
18584 KB |
Output is correct |
13 |
Correct |
279 ms |
18864 KB |
Output is correct |
14 |
Correct |
263 ms |
18848 KB |
Output is correct |
15 |
Correct |
274 ms |
18836 KB |
Output is correct |
16 |
Correct |
267 ms |
18840 KB |
Output is correct |
17 |
Correct |
268 ms |
18852 KB |
Output is correct |
18 |
Correct |
279 ms |
19096 KB |
Output is correct |
19 |
Correct |
264 ms |
18716 KB |
Output is correct |
20 |
Correct |
288 ms |
18840 KB |
Output is correct |
21 |
Correct |
265 ms |
18848 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
261 ms |
18860 KB |
Output is correct |
2 |
Correct |
276 ms |
18716 KB |
Output is correct |
3 |
Correct |
266 ms |
18860 KB |
Output is correct |
4 |
Correct |
313 ms |
18580 KB |
Output is correct |
5 |
Correct |
267 ms |
18856 KB |
Output is correct |
6 |
Correct |
272 ms |
18804 KB |
Output is correct |
7 |
Correct |
263 ms |
18716 KB |
Output is correct |
8 |
Correct |
284 ms |
18868 KB |
Output is correct |
9 |
Correct |
293 ms |
18844 KB |
Output is correct |
10 |
Correct |
264 ms |
18780 KB |
Output is correct |
11 |
Correct |
279 ms |
19032 KB |
Output is correct |
12 |
Correct |
288 ms |
18584 KB |
Output is correct |
13 |
Correct |
279 ms |
18864 KB |
Output is correct |
14 |
Correct |
263 ms |
18848 KB |
Output is correct |
15 |
Correct |
274 ms |
18836 KB |
Output is correct |
16 |
Correct |
267 ms |
18840 KB |
Output is correct |
17 |
Correct |
268 ms |
18852 KB |
Output is correct |
18 |
Correct |
279 ms |
19096 KB |
Output is correct |
19 |
Correct |
264 ms |
18716 KB |
Output is correct |
20 |
Correct |
288 ms |
18840 KB |
Output is correct |
21 |
Correct |
265 ms |
18848 KB |
Output is correct |
22 |
Correct |
264 ms |
19660 KB |
Output is correct |
23 |
Correct |
282 ms |
19636 KB |
Output is correct |
24 |
Correct |
287 ms |
19604 KB |
Output is correct |
25 |
Correct |
291 ms |
19500 KB |
Output is correct |
26 |
Correct |
259 ms |
19460 KB |
Output is correct |
27 |
Correct |
287 ms |
19624 KB |
Output is correct |
28 |
Correct |
275 ms |
19676 KB |
Output is correct |
29 |
Correct |
269 ms |
19484 KB |
Output is correct |
30 |
Correct |
258 ms |
19500 KB |
Output is correct |
31 |
Correct |
285 ms |
19484 KB |
Output is correct |
32 |
Correct |
260 ms |
19484 KB |
Output is correct |
33 |
Correct |
266 ms |
19632 KB |
Output is correct |
34 |
Correct |
260 ms |
19488 KB |
Output is correct |
35 |
Correct |
259 ms |
19492 KB |
Output is correct |
36 |
Correct |
278 ms |
19620 KB |
Output is correct |
37 |
Correct |
263 ms |
19552 KB |
Output is correct |
38 |
Correct |
274 ms |
19640 KB |
Output is correct |
39 |
Correct |
264 ms |
19484 KB |
Output is correct |
40 |
Correct |
261 ms |
19608 KB |
Output is correct |
41 |
Correct |
266 ms |
19644 KB |
Output is correct |
42 |
Correct |
274 ms |
19600 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
261 ms |
18860 KB |
Output is correct |
2 |
Correct |
276 ms |
18716 KB |
Output is correct |
3 |
Correct |
266 ms |
18860 KB |
Output is correct |
4 |
Correct |
313 ms |
18580 KB |
Output is correct |
5 |
Correct |
267 ms |
18856 KB |
Output is correct |
6 |
Correct |
272 ms |
18804 KB |
Output is correct |
7 |
Correct |
263 ms |
18716 KB |
Output is correct |
8 |
Correct |
284 ms |
18868 KB |
Output is correct |
9 |
Correct |
293 ms |
18844 KB |
Output is correct |
10 |
Correct |
264 ms |
18780 KB |
Output is correct |
11 |
Correct |
279 ms |
19032 KB |
Output is correct |
12 |
Correct |
288 ms |
18584 KB |
Output is correct |
13 |
Correct |
279 ms |
18864 KB |
Output is correct |
14 |
Correct |
263 ms |
18848 KB |
Output is correct |
15 |
Correct |
274 ms |
18836 KB |
Output is correct |
16 |
Correct |
267 ms |
18840 KB |
Output is correct |
17 |
Correct |
268 ms |
18852 KB |
Output is correct |
18 |
Correct |
279 ms |
19096 KB |
Output is correct |
19 |
Correct |
264 ms |
18716 KB |
Output is correct |
20 |
Correct |
288 ms |
18840 KB |
Output is correct |
21 |
Correct |
265 ms |
18848 KB |
Output is correct |
22 |
Correct |
264 ms |
19660 KB |
Output is correct |
23 |
Correct |
282 ms |
19636 KB |
Output is correct |
24 |
Correct |
287 ms |
19604 KB |
Output is correct |
25 |
Correct |
291 ms |
19500 KB |
Output is correct |
26 |
Correct |
259 ms |
19460 KB |
Output is correct |
27 |
Correct |
287 ms |
19624 KB |
Output is correct |
28 |
Correct |
275 ms |
19676 KB |
Output is correct |
29 |
Correct |
269 ms |
19484 KB |
Output is correct |
30 |
Correct |
258 ms |
19500 KB |
Output is correct |
31 |
Correct |
285 ms |
19484 KB |
Output is correct |
32 |
Correct |
260 ms |
19484 KB |
Output is correct |
33 |
Correct |
266 ms |
19632 KB |
Output is correct |
34 |
Correct |
260 ms |
19488 KB |
Output is correct |
35 |
Correct |
259 ms |
19492 KB |
Output is correct |
36 |
Correct |
278 ms |
19620 KB |
Output is correct |
37 |
Correct |
263 ms |
19552 KB |
Output is correct |
38 |
Correct |
274 ms |
19640 KB |
Output is correct |
39 |
Correct |
264 ms |
19484 KB |
Output is correct |
40 |
Correct |
261 ms |
19608 KB |
Output is correct |
41 |
Correct |
266 ms |
19644 KB |
Output is correct |
42 |
Correct |
274 ms |
19600 KB |
Output is correct |
43 |
Correct |
281 ms |
19908 KB |
Output is correct |
44 |
Correct |
272 ms |
19924 KB |
Output is correct |
45 |
Correct |
270 ms |
19896 KB |
Output is correct |
46 |
Correct |
260 ms |
19864 KB |
Output is correct |
47 |
Correct |
261 ms |
19884 KB |
Output is correct |
48 |
Correct |
284 ms |
19924 KB |
Output is correct |
49 |
Correct |
271 ms |
19752 KB |
Output is correct |
50 |
Correct |
258 ms |
19828 KB |
Output is correct |
51 |
Correct |
267 ms |
20028 KB |
Output is correct |
52 |
Correct |
261 ms |
19868 KB |
Output is correct |
53 |
Correct |
281 ms |
20136 KB |
Output is correct |
54 |
Correct |
260 ms |
19824 KB |
Output is correct |
55 |
Correct |
280 ms |
19896 KB |
Output is correct |
56 |
Correct |
265 ms |
19912 KB |
Output is correct |
57 |
Correct |
271 ms |
19640 KB |
Output is correct |
58 |
Correct |
280 ms |
19808 KB |
Output is correct |
59 |
Correct |
268 ms |
19648 KB |
Output is correct |
60 |
Correct |
304 ms |
19864 KB |
Output is correct |
61 |
Correct |
261 ms |
19864 KB |
Output is correct |
62 |
Correct |
269 ms |
19888 KB |
Output is correct |
63 |
Correct |
269 ms |
19684 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
261 ms |
18860 KB |
Output is correct |
2 |
Correct |
276 ms |
18716 KB |
Output is correct |
3 |
Correct |
266 ms |
18860 KB |
Output is correct |
4 |
Correct |
313 ms |
18580 KB |
Output is correct |
5 |
Correct |
267 ms |
18856 KB |
Output is correct |
6 |
Correct |
272 ms |
18804 KB |
Output is correct |
7 |
Correct |
263 ms |
18716 KB |
Output is correct |
8 |
Correct |
284 ms |
18868 KB |
Output is correct |
9 |
Correct |
293 ms |
18844 KB |
Output is correct |
10 |
Correct |
264 ms |
18780 KB |
Output is correct |
11 |
Correct |
279 ms |
19032 KB |
Output is correct |
12 |
Correct |
288 ms |
18584 KB |
Output is correct |
13 |
Correct |
279 ms |
18864 KB |
Output is correct |
14 |
Correct |
263 ms |
18848 KB |
Output is correct |
15 |
Correct |
274 ms |
18836 KB |
Output is correct |
16 |
Correct |
267 ms |
18840 KB |
Output is correct |
17 |
Correct |
268 ms |
18852 KB |
Output is correct |
18 |
Correct |
279 ms |
19096 KB |
Output is correct |
19 |
Correct |
264 ms |
18716 KB |
Output is correct |
20 |
Correct |
288 ms |
18840 KB |
Output is correct |
21 |
Correct |
265 ms |
18848 KB |
Output is correct |
22 |
Correct |
264 ms |
19660 KB |
Output is correct |
23 |
Correct |
282 ms |
19636 KB |
Output is correct |
24 |
Correct |
287 ms |
19604 KB |
Output is correct |
25 |
Correct |
291 ms |
19500 KB |
Output is correct |
26 |
Correct |
259 ms |
19460 KB |
Output is correct |
27 |
Correct |
287 ms |
19624 KB |
Output is correct |
28 |
Correct |
275 ms |
19676 KB |
Output is correct |
29 |
Correct |
269 ms |
19484 KB |
Output is correct |
30 |
Correct |
258 ms |
19500 KB |
Output is correct |
31 |
Correct |
285 ms |
19484 KB |
Output is correct |
32 |
Correct |
260 ms |
19484 KB |
Output is correct |
33 |
Correct |
266 ms |
19632 KB |
Output is correct |
34 |
Correct |
260 ms |
19488 KB |
Output is correct |
35 |
Correct |
259 ms |
19492 KB |
Output is correct |
36 |
Correct |
278 ms |
19620 KB |
Output is correct |
37 |
Correct |
263 ms |
19552 KB |
Output is correct |
38 |
Correct |
274 ms |
19640 KB |
Output is correct |
39 |
Correct |
264 ms |
19484 KB |
Output is correct |
40 |
Correct |
261 ms |
19608 KB |
Output is correct |
41 |
Correct |
266 ms |
19644 KB |
Output is correct |
42 |
Correct |
274 ms |
19600 KB |
Output is correct |
43 |
Correct |
281 ms |
19908 KB |
Output is correct |
44 |
Correct |
272 ms |
19924 KB |
Output is correct |
45 |
Correct |
270 ms |
19896 KB |
Output is correct |
46 |
Correct |
260 ms |
19864 KB |
Output is correct |
47 |
Correct |
261 ms |
19884 KB |
Output is correct |
48 |
Correct |
284 ms |
19924 KB |
Output is correct |
49 |
Correct |
271 ms |
19752 KB |
Output is correct |
50 |
Correct |
258 ms |
19828 KB |
Output is correct |
51 |
Correct |
267 ms |
20028 KB |
Output is correct |
52 |
Correct |
261 ms |
19868 KB |
Output is correct |
53 |
Correct |
281 ms |
20136 KB |
Output is correct |
54 |
Correct |
260 ms |
19824 KB |
Output is correct |
55 |
Correct |
280 ms |
19896 KB |
Output is correct |
56 |
Correct |
265 ms |
19912 KB |
Output is correct |
57 |
Correct |
271 ms |
19640 KB |
Output is correct |
58 |
Correct |
280 ms |
19808 KB |
Output is correct |
59 |
Correct |
268 ms |
19648 KB |
Output is correct |
60 |
Correct |
304 ms |
19864 KB |
Output is correct |
61 |
Correct |
261 ms |
19864 KB |
Output is correct |
62 |
Correct |
269 ms |
19888 KB |
Output is correct |
63 |
Correct |
269 ms |
19684 KB |
Output is correct |
64 |
Correct |
294 ms |
20180 KB |
Output is correct |
65 |
Correct |
298 ms |
20848 KB |
Output is correct |
66 |
Correct |
300 ms |
20908 KB |
Output is correct |
67 |
Correct |
303 ms |
20944 KB |
Output is correct |
68 |
Correct |
297 ms |
20760 KB |
Output is correct |
69 |
Correct |
299 ms |
21144 KB |
Output is correct |
70 |
Correct |
292 ms |
20752 KB |
Output is correct |
71 |
Correct |
292 ms |
20764 KB |
Output is correct |
72 |
Correct |
307 ms |
20876 KB |
Output is correct |
73 |
Correct |
294 ms |
20852 KB |
Output is correct |
74 |
Correct |
307 ms |
21048 KB |
Output is correct |
75 |
Correct |
293 ms |
20904 KB |
Output is correct |
76 |
Correct |
337 ms |
20916 KB |
Output is correct |
77 |
Correct |
303 ms |
20828 KB |
Output is correct |
78 |
Correct |
309 ms |
21080 KB |
Output is correct |
79 |
Correct |
304 ms |
20864 KB |
Output is correct |
80 |
Correct |
306 ms |
20752 KB |
Output is correct |
81 |
Correct |
310 ms |
20904 KB |
Output is correct |
82 |
Correct |
330 ms |
20856 KB |
Output is correct |
83 |
Correct |
314 ms |
20920 KB |
Output is correct |
84 |
Correct |
310 ms |
20848 KB |
Output is correct |