#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,fma")
#include <bits/stdc++.h>
using namespace std;
constexpr int maxn = 32, mod = 998244353; // subtasks 1-2
int ans;
int edge[11][maxn][maxn];
int value_triad[11][maxn][maxn][maxn];
int id(char c) { return c-'a'; } // subtaks 1-2
set<string> mark;
void add(int& a, int b) { a += b; if(a >= mod) a -= mod; }
int D[11][maxn][maxn][maxn];
int main() {
int n; cin >> n;
string s;
for(int i = 0; i < n; i++) {
cin >> s;
for(int rep = 0; rep < 2; rep++, reverse(s.begin(), s.end())) if(!mark.count(s)) {
edge[s.size()][id(s[0])][id(s.back())]++;
mark.insert(s);
}
}
for(int sz = 3; sz <= 10; sz++)
for(int a = 0; a < maxn; a++) for(int b = 0; b < maxn; b++) for(int c = 0; c < maxn; c++)
for(int x = 0; x < maxn; x++)
add(D[sz][a][b][c], 1ll * edge[sz][x][a] * edge[sz][x][b] % mod * edge[sz][x][c] % mod);
for(int sz = 3; sz <= 10; sz++) {
for(int a = 0; a < maxn; a++) for(int b = 0; b < maxn; b++) for(int c = 0; c < maxn; c++) for(int d = 0; d < maxn; d++)
add(ans, 1ll * D[sz][a][b][c] * D[sz][a][b][d] % mod * D[sz][a][c][d] % mod * D[sz][b][c][d] % mod);
}
printf("%d\n", ans);
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
281 ms |
15852 KB |
Output is correct |
2 |
Correct |
299 ms |
15824 KB |
Output is correct |
3 |
Correct |
297 ms |
15764 KB |
Output is correct |
4 |
Correct |
271 ms |
15820 KB |
Output is correct |
5 |
Correct |
328 ms |
15824 KB |
Output is correct |
6 |
Correct |
281 ms |
15836 KB |
Output is correct |
7 |
Correct |
304 ms |
15820 KB |
Output is correct |
8 |
Correct |
265 ms |
15816 KB |
Output is correct |
9 |
Correct |
295 ms |
15828 KB |
Output is correct |
10 |
Correct |
288 ms |
15824 KB |
Output is correct |
11 |
Correct |
282 ms |
15836 KB |
Output is correct |
12 |
Correct |
320 ms |
15776 KB |
Output is correct |
13 |
Correct |
265 ms |
15820 KB |
Output is correct |
14 |
Correct |
293 ms |
15776 KB |
Output is correct |
15 |
Correct |
286 ms |
15916 KB |
Output is correct |
16 |
Correct |
297 ms |
15868 KB |
Output is correct |
17 |
Correct |
296 ms |
15920 KB |
Output is correct |
18 |
Correct |
265 ms |
15708 KB |
Output is correct |
19 |
Correct |
284 ms |
15776 KB |
Output is correct |
20 |
Correct |
285 ms |
15840 KB |
Output is correct |
21 |
Correct |
274 ms |
15896 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
281 ms |
15852 KB |
Output is correct |
2 |
Correct |
299 ms |
15824 KB |
Output is correct |
3 |
Correct |
297 ms |
15764 KB |
Output is correct |
4 |
Correct |
271 ms |
15820 KB |
Output is correct |
5 |
Correct |
328 ms |
15824 KB |
Output is correct |
6 |
Correct |
281 ms |
15836 KB |
Output is correct |
7 |
Correct |
304 ms |
15820 KB |
Output is correct |
8 |
Correct |
265 ms |
15816 KB |
Output is correct |
9 |
Correct |
295 ms |
15828 KB |
Output is correct |
10 |
Correct |
288 ms |
15824 KB |
Output is correct |
11 |
Correct |
282 ms |
15836 KB |
Output is correct |
12 |
Correct |
320 ms |
15776 KB |
Output is correct |
13 |
Correct |
265 ms |
15820 KB |
Output is correct |
14 |
Correct |
293 ms |
15776 KB |
Output is correct |
15 |
Correct |
286 ms |
15916 KB |
Output is correct |
16 |
Correct |
297 ms |
15868 KB |
Output is correct |
17 |
Correct |
296 ms |
15920 KB |
Output is correct |
18 |
Correct |
265 ms |
15708 KB |
Output is correct |
19 |
Correct |
284 ms |
15776 KB |
Output is correct |
20 |
Correct |
285 ms |
15840 KB |
Output is correct |
21 |
Correct |
274 ms |
15896 KB |
Output is correct |
22 |
Correct |
296 ms |
16464 KB |
Output is correct |
23 |
Correct |
303 ms |
16488 KB |
Output is correct |
24 |
Correct |
336 ms |
16504 KB |
Output is correct |
25 |
Correct |
287 ms |
16484 KB |
Output is correct |
26 |
Correct |
290 ms |
16480 KB |
Output is correct |
27 |
Correct |
295 ms |
16588 KB |
Output is correct |
28 |
Correct |
263 ms |
16460 KB |
Output is correct |
29 |
Correct |
298 ms |
16496 KB |
Output is correct |
30 |
Correct |
317 ms |
16484 KB |
Output is correct |
31 |
Correct |
314 ms |
16596 KB |
Output is correct |
32 |
Correct |
264 ms |
16424 KB |
Output is correct |
33 |
Correct |
288 ms |
16488 KB |
Output is correct |
34 |
Correct |
271 ms |
16372 KB |
Output is correct |
35 |
Correct |
273 ms |
16496 KB |
Output is correct |
36 |
Correct |
278 ms |
16392 KB |
Output is correct |
37 |
Correct |
268 ms |
16456 KB |
Output is correct |
38 |
Correct |
332 ms |
16460 KB |
Output is correct |
39 |
Correct |
267 ms |
16460 KB |
Output is correct |
40 |
Correct |
290 ms |
16488 KB |
Output is correct |
41 |
Correct |
268 ms |
16396 KB |
Output is correct |
42 |
Correct |
295 ms |
16500 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
281 ms |
15852 KB |
Output is correct |
2 |
Correct |
299 ms |
15824 KB |
Output is correct |
3 |
Correct |
297 ms |
15764 KB |
Output is correct |
4 |
Correct |
271 ms |
15820 KB |
Output is correct |
5 |
Correct |
328 ms |
15824 KB |
Output is correct |
6 |
Correct |
281 ms |
15836 KB |
Output is correct |
7 |
Correct |
304 ms |
15820 KB |
Output is correct |
8 |
Correct |
265 ms |
15816 KB |
Output is correct |
9 |
Correct |
295 ms |
15828 KB |
Output is correct |
10 |
Correct |
288 ms |
15824 KB |
Output is correct |
11 |
Correct |
282 ms |
15836 KB |
Output is correct |
12 |
Correct |
320 ms |
15776 KB |
Output is correct |
13 |
Correct |
265 ms |
15820 KB |
Output is correct |
14 |
Correct |
293 ms |
15776 KB |
Output is correct |
15 |
Correct |
286 ms |
15916 KB |
Output is correct |
16 |
Correct |
297 ms |
15868 KB |
Output is correct |
17 |
Correct |
296 ms |
15920 KB |
Output is correct |
18 |
Correct |
265 ms |
15708 KB |
Output is correct |
19 |
Correct |
284 ms |
15776 KB |
Output is correct |
20 |
Correct |
285 ms |
15840 KB |
Output is correct |
21 |
Correct |
274 ms |
15896 KB |
Output is correct |
22 |
Correct |
296 ms |
16464 KB |
Output is correct |
23 |
Correct |
303 ms |
16488 KB |
Output is correct |
24 |
Correct |
336 ms |
16504 KB |
Output is correct |
25 |
Correct |
287 ms |
16484 KB |
Output is correct |
26 |
Correct |
290 ms |
16480 KB |
Output is correct |
27 |
Correct |
295 ms |
16588 KB |
Output is correct |
28 |
Correct |
263 ms |
16460 KB |
Output is correct |
29 |
Correct |
298 ms |
16496 KB |
Output is correct |
30 |
Correct |
317 ms |
16484 KB |
Output is correct |
31 |
Correct |
314 ms |
16596 KB |
Output is correct |
32 |
Correct |
264 ms |
16424 KB |
Output is correct |
33 |
Correct |
288 ms |
16488 KB |
Output is correct |
34 |
Correct |
271 ms |
16372 KB |
Output is correct |
35 |
Correct |
273 ms |
16496 KB |
Output is correct |
36 |
Correct |
278 ms |
16392 KB |
Output is correct |
37 |
Correct |
268 ms |
16456 KB |
Output is correct |
38 |
Correct |
332 ms |
16460 KB |
Output is correct |
39 |
Correct |
267 ms |
16460 KB |
Output is correct |
40 |
Correct |
290 ms |
16488 KB |
Output is correct |
41 |
Correct |
268 ms |
16396 KB |
Output is correct |
42 |
Correct |
295 ms |
16500 KB |
Output is correct |
43 |
Incorrect |
296 ms |
16704 KB |
Output isn't correct |
44 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
281 ms |
15852 KB |
Output is correct |
2 |
Correct |
299 ms |
15824 KB |
Output is correct |
3 |
Correct |
297 ms |
15764 KB |
Output is correct |
4 |
Correct |
271 ms |
15820 KB |
Output is correct |
5 |
Correct |
328 ms |
15824 KB |
Output is correct |
6 |
Correct |
281 ms |
15836 KB |
Output is correct |
7 |
Correct |
304 ms |
15820 KB |
Output is correct |
8 |
Correct |
265 ms |
15816 KB |
Output is correct |
9 |
Correct |
295 ms |
15828 KB |
Output is correct |
10 |
Correct |
288 ms |
15824 KB |
Output is correct |
11 |
Correct |
282 ms |
15836 KB |
Output is correct |
12 |
Correct |
320 ms |
15776 KB |
Output is correct |
13 |
Correct |
265 ms |
15820 KB |
Output is correct |
14 |
Correct |
293 ms |
15776 KB |
Output is correct |
15 |
Correct |
286 ms |
15916 KB |
Output is correct |
16 |
Correct |
297 ms |
15868 KB |
Output is correct |
17 |
Correct |
296 ms |
15920 KB |
Output is correct |
18 |
Correct |
265 ms |
15708 KB |
Output is correct |
19 |
Correct |
284 ms |
15776 KB |
Output is correct |
20 |
Correct |
285 ms |
15840 KB |
Output is correct |
21 |
Correct |
274 ms |
15896 KB |
Output is correct |
22 |
Correct |
296 ms |
16464 KB |
Output is correct |
23 |
Correct |
303 ms |
16488 KB |
Output is correct |
24 |
Correct |
336 ms |
16504 KB |
Output is correct |
25 |
Correct |
287 ms |
16484 KB |
Output is correct |
26 |
Correct |
290 ms |
16480 KB |
Output is correct |
27 |
Correct |
295 ms |
16588 KB |
Output is correct |
28 |
Correct |
263 ms |
16460 KB |
Output is correct |
29 |
Correct |
298 ms |
16496 KB |
Output is correct |
30 |
Correct |
317 ms |
16484 KB |
Output is correct |
31 |
Correct |
314 ms |
16596 KB |
Output is correct |
32 |
Correct |
264 ms |
16424 KB |
Output is correct |
33 |
Correct |
288 ms |
16488 KB |
Output is correct |
34 |
Correct |
271 ms |
16372 KB |
Output is correct |
35 |
Correct |
273 ms |
16496 KB |
Output is correct |
36 |
Correct |
278 ms |
16392 KB |
Output is correct |
37 |
Correct |
268 ms |
16456 KB |
Output is correct |
38 |
Correct |
332 ms |
16460 KB |
Output is correct |
39 |
Correct |
267 ms |
16460 KB |
Output is correct |
40 |
Correct |
290 ms |
16488 KB |
Output is correct |
41 |
Correct |
268 ms |
16396 KB |
Output is correct |
42 |
Correct |
295 ms |
16500 KB |
Output is correct |
43 |
Incorrect |
296 ms |
16704 KB |
Output isn't correct |
44 |
Halted |
0 ms |
0 KB |
- |