#include <bits/stdc++.h>
using namespace std;
const int BASE = 998244353;
const int N = 62;
int toInt(char c)
{
if (c >= 'a' && c <= 'z')
return c - 'a';
if (c >= 'A' && c <= 'Z')
return c - 'A' + 26;
return c - '0' + 52;
}
long long solve(set<string> a)
{
int cnt[N][N] = {0};
int f[N][N][N] = {0};
for (auto s : a)
{
int x = toInt(s[0]), y = toInt(s.back());
cnt[x][y]++;
}
for (int i = 0; i < N; i++)
for (int j = i; j < N; j++)
for (int p = j; p < N; p++)
for (int q = 0; q < N; q++)
{
long long ways = 1LL * cnt[i][q] * cnt[j][q] % BASE * cnt[p][q] % BASE;
f[i][j][p] += ways;
if (f[i][j][p] >= BASE)
f[i][j][p] -= BASE;
}
long long res = 0;
for (int i = 0; i < N; i++)
for (int j = i; j < N; j++)
for (int p = j; p < N; p++)
for (int q = p; q < N; q++)
{
long long ways = 1LL * f[i][j][p] * f[i][j][q] % BASE;
ways = ways * f[i][p][q] % BASE;
ways = ways * f[j][p][q] % BASE;
if (i == q) res += ways;
else if (i == p || j == q) res += ways * 4;
else if (i == j && p == q) res += ways * 6;
else if (i == j || j == p || p == q) res += ways * 12;
else res += ways * 24;
res %= BASE;
}
return res;
}
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
int n;
string s;
set<string> a[11];
cin >> n;
while (n--)
{
cin >> s;
a[s.size()].insert(s);
reverse(s.begin(), s.end());
a[s.size()].insert(s);
}
long long ans = 0;
for (int i = 3; i <= 10; i++)
ans = (ans + solve(a[i])) % BASE;
cout << ans << endl;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
342 ms |
19656 KB |
Output is correct |
2 |
Correct |
341 ms |
19544 KB |
Output is correct |
3 |
Correct |
351 ms |
19608 KB |
Output is correct |
4 |
Correct |
362 ms |
19536 KB |
Output is correct |
5 |
Correct |
338 ms |
19472 KB |
Output is correct |
6 |
Correct |
351 ms |
19560 KB |
Output is correct |
7 |
Correct |
347 ms |
19528 KB |
Output is correct |
8 |
Correct |
367 ms |
19516 KB |
Output is correct |
9 |
Correct |
348 ms |
19580 KB |
Output is correct |
10 |
Correct |
350 ms |
19524 KB |
Output is correct |
11 |
Correct |
342 ms |
19620 KB |
Output is correct |
12 |
Correct |
340 ms |
19480 KB |
Output is correct |
13 |
Correct |
339 ms |
19540 KB |
Output is correct |
14 |
Correct |
337 ms |
19496 KB |
Output is correct |
15 |
Correct |
352 ms |
19632 KB |
Output is correct |
16 |
Correct |
352 ms |
19452 KB |
Output is correct |
17 |
Correct |
332 ms |
19560 KB |
Output is correct |
18 |
Correct |
341 ms |
19676 KB |
Output is correct |
19 |
Correct |
343 ms |
19552 KB |
Output is correct |
20 |
Correct |
330 ms |
19524 KB |
Output is correct |
21 |
Correct |
362 ms |
19560 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
342 ms |
19656 KB |
Output is correct |
2 |
Correct |
341 ms |
19544 KB |
Output is correct |
3 |
Correct |
351 ms |
19608 KB |
Output is correct |
4 |
Correct |
362 ms |
19536 KB |
Output is correct |
5 |
Correct |
338 ms |
19472 KB |
Output is correct |
6 |
Correct |
351 ms |
19560 KB |
Output is correct |
7 |
Correct |
347 ms |
19528 KB |
Output is correct |
8 |
Correct |
367 ms |
19516 KB |
Output is correct |
9 |
Correct |
348 ms |
19580 KB |
Output is correct |
10 |
Correct |
350 ms |
19524 KB |
Output is correct |
11 |
Correct |
342 ms |
19620 KB |
Output is correct |
12 |
Correct |
340 ms |
19480 KB |
Output is correct |
13 |
Correct |
339 ms |
19540 KB |
Output is correct |
14 |
Correct |
337 ms |
19496 KB |
Output is correct |
15 |
Correct |
352 ms |
19632 KB |
Output is correct |
16 |
Correct |
352 ms |
19452 KB |
Output is correct |
17 |
Correct |
332 ms |
19560 KB |
Output is correct |
18 |
Correct |
341 ms |
19676 KB |
Output is correct |
19 |
Correct |
343 ms |
19552 KB |
Output is correct |
20 |
Correct |
330 ms |
19524 KB |
Output is correct |
21 |
Correct |
362 ms |
19560 KB |
Output is correct |
22 |
Correct |
349 ms |
19476 KB |
Output is correct |
23 |
Correct |
336 ms |
19336 KB |
Output is correct |
24 |
Correct |
367 ms |
19364 KB |
Output is correct |
25 |
Correct |
362 ms |
19348 KB |
Output is correct |
26 |
Correct |
331 ms |
19312 KB |
Output is correct |
27 |
Correct |
340 ms |
19328 KB |
Output is correct |
28 |
Correct |
338 ms |
19376 KB |
Output is correct |
29 |
Correct |
336 ms |
19468 KB |
Output is correct |
30 |
Correct |
336 ms |
19236 KB |
Output is correct |
31 |
Correct |
338 ms |
19344 KB |
Output is correct |
32 |
Correct |
359 ms |
19496 KB |
Output is correct |
33 |
Correct |
339 ms |
19368 KB |
Output is correct |
34 |
Correct |
345 ms |
19460 KB |
Output is correct |
35 |
Correct |
335 ms |
19336 KB |
Output is correct |
36 |
Correct |
347 ms |
19432 KB |
Output is correct |
37 |
Correct |
332 ms |
19292 KB |
Output is correct |
38 |
Correct |
340 ms |
19448 KB |
Output is correct |
39 |
Correct |
332 ms |
19224 KB |
Output is correct |
40 |
Correct |
357 ms |
19232 KB |
Output is correct |
41 |
Correct |
340 ms |
19316 KB |
Output is correct |
42 |
Correct |
345 ms |
19468 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
342 ms |
19656 KB |
Output is correct |
2 |
Correct |
341 ms |
19544 KB |
Output is correct |
3 |
Correct |
351 ms |
19608 KB |
Output is correct |
4 |
Correct |
362 ms |
19536 KB |
Output is correct |
5 |
Correct |
338 ms |
19472 KB |
Output is correct |
6 |
Correct |
351 ms |
19560 KB |
Output is correct |
7 |
Correct |
347 ms |
19528 KB |
Output is correct |
8 |
Correct |
367 ms |
19516 KB |
Output is correct |
9 |
Correct |
348 ms |
19580 KB |
Output is correct |
10 |
Correct |
350 ms |
19524 KB |
Output is correct |
11 |
Correct |
342 ms |
19620 KB |
Output is correct |
12 |
Correct |
340 ms |
19480 KB |
Output is correct |
13 |
Correct |
339 ms |
19540 KB |
Output is correct |
14 |
Correct |
337 ms |
19496 KB |
Output is correct |
15 |
Correct |
352 ms |
19632 KB |
Output is correct |
16 |
Correct |
352 ms |
19452 KB |
Output is correct |
17 |
Correct |
332 ms |
19560 KB |
Output is correct |
18 |
Correct |
341 ms |
19676 KB |
Output is correct |
19 |
Correct |
343 ms |
19552 KB |
Output is correct |
20 |
Correct |
330 ms |
19524 KB |
Output is correct |
21 |
Correct |
362 ms |
19560 KB |
Output is correct |
22 |
Correct |
349 ms |
19476 KB |
Output is correct |
23 |
Correct |
336 ms |
19336 KB |
Output is correct |
24 |
Correct |
367 ms |
19364 KB |
Output is correct |
25 |
Correct |
362 ms |
19348 KB |
Output is correct |
26 |
Correct |
331 ms |
19312 KB |
Output is correct |
27 |
Correct |
340 ms |
19328 KB |
Output is correct |
28 |
Correct |
338 ms |
19376 KB |
Output is correct |
29 |
Correct |
336 ms |
19468 KB |
Output is correct |
30 |
Correct |
336 ms |
19236 KB |
Output is correct |
31 |
Correct |
338 ms |
19344 KB |
Output is correct |
32 |
Correct |
359 ms |
19496 KB |
Output is correct |
33 |
Correct |
339 ms |
19368 KB |
Output is correct |
34 |
Correct |
345 ms |
19460 KB |
Output is correct |
35 |
Correct |
335 ms |
19336 KB |
Output is correct |
36 |
Correct |
347 ms |
19432 KB |
Output is correct |
37 |
Correct |
332 ms |
19292 KB |
Output is correct |
38 |
Correct |
340 ms |
19448 KB |
Output is correct |
39 |
Correct |
332 ms |
19224 KB |
Output is correct |
40 |
Correct |
357 ms |
19232 KB |
Output is correct |
41 |
Correct |
340 ms |
19316 KB |
Output is correct |
42 |
Correct |
345 ms |
19468 KB |
Output is correct |
43 |
Correct |
347 ms |
19356 KB |
Output is correct |
44 |
Correct |
350 ms |
19364 KB |
Output is correct |
45 |
Correct |
334 ms |
19336 KB |
Output is correct |
46 |
Correct |
344 ms |
19416 KB |
Output is correct |
47 |
Correct |
358 ms |
19288 KB |
Output is correct |
48 |
Correct |
348 ms |
19424 KB |
Output is correct |
49 |
Correct |
338 ms |
19404 KB |
Output is correct |
50 |
Correct |
336 ms |
19312 KB |
Output is correct |
51 |
Correct |
330 ms |
19332 KB |
Output is correct |
52 |
Correct |
349 ms |
19304 KB |
Output is correct |
53 |
Correct |
344 ms |
19356 KB |
Output is correct |
54 |
Correct |
342 ms |
19436 KB |
Output is correct |
55 |
Correct |
345 ms |
19340 KB |
Output is correct |
56 |
Correct |
336 ms |
19452 KB |
Output is correct |
57 |
Correct |
336 ms |
19224 KB |
Output is correct |
58 |
Correct |
349 ms |
19396 KB |
Output is correct |
59 |
Correct |
333 ms |
19348 KB |
Output is correct |
60 |
Correct |
356 ms |
19344 KB |
Output is correct |
61 |
Correct |
373 ms |
19380 KB |
Output is correct |
62 |
Correct |
335 ms |
19284 KB |
Output is correct |
63 |
Correct |
335 ms |
19256 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
342 ms |
19656 KB |
Output is correct |
2 |
Correct |
341 ms |
19544 KB |
Output is correct |
3 |
Correct |
351 ms |
19608 KB |
Output is correct |
4 |
Correct |
362 ms |
19536 KB |
Output is correct |
5 |
Correct |
338 ms |
19472 KB |
Output is correct |
6 |
Correct |
351 ms |
19560 KB |
Output is correct |
7 |
Correct |
347 ms |
19528 KB |
Output is correct |
8 |
Correct |
367 ms |
19516 KB |
Output is correct |
9 |
Correct |
348 ms |
19580 KB |
Output is correct |
10 |
Correct |
350 ms |
19524 KB |
Output is correct |
11 |
Correct |
342 ms |
19620 KB |
Output is correct |
12 |
Correct |
340 ms |
19480 KB |
Output is correct |
13 |
Correct |
339 ms |
19540 KB |
Output is correct |
14 |
Correct |
337 ms |
19496 KB |
Output is correct |
15 |
Correct |
352 ms |
19632 KB |
Output is correct |
16 |
Correct |
352 ms |
19452 KB |
Output is correct |
17 |
Correct |
332 ms |
19560 KB |
Output is correct |
18 |
Correct |
341 ms |
19676 KB |
Output is correct |
19 |
Correct |
343 ms |
19552 KB |
Output is correct |
20 |
Correct |
330 ms |
19524 KB |
Output is correct |
21 |
Correct |
362 ms |
19560 KB |
Output is correct |
22 |
Correct |
349 ms |
19476 KB |
Output is correct |
23 |
Correct |
336 ms |
19336 KB |
Output is correct |
24 |
Correct |
367 ms |
19364 KB |
Output is correct |
25 |
Correct |
362 ms |
19348 KB |
Output is correct |
26 |
Correct |
331 ms |
19312 KB |
Output is correct |
27 |
Correct |
340 ms |
19328 KB |
Output is correct |
28 |
Correct |
338 ms |
19376 KB |
Output is correct |
29 |
Correct |
336 ms |
19468 KB |
Output is correct |
30 |
Correct |
336 ms |
19236 KB |
Output is correct |
31 |
Correct |
338 ms |
19344 KB |
Output is correct |
32 |
Correct |
359 ms |
19496 KB |
Output is correct |
33 |
Correct |
339 ms |
19368 KB |
Output is correct |
34 |
Correct |
345 ms |
19460 KB |
Output is correct |
35 |
Correct |
335 ms |
19336 KB |
Output is correct |
36 |
Correct |
347 ms |
19432 KB |
Output is correct |
37 |
Correct |
332 ms |
19292 KB |
Output is correct |
38 |
Correct |
340 ms |
19448 KB |
Output is correct |
39 |
Correct |
332 ms |
19224 KB |
Output is correct |
40 |
Correct |
357 ms |
19232 KB |
Output is correct |
41 |
Correct |
340 ms |
19316 KB |
Output is correct |
42 |
Correct |
345 ms |
19468 KB |
Output is correct |
43 |
Correct |
347 ms |
19356 KB |
Output is correct |
44 |
Correct |
350 ms |
19364 KB |
Output is correct |
45 |
Correct |
334 ms |
19336 KB |
Output is correct |
46 |
Correct |
344 ms |
19416 KB |
Output is correct |
47 |
Correct |
358 ms |
19288 KB |
Output is correct |
48 |
Correct |
348 ms |
19424 KB |
Output is correct |
49 |
Correct |
338 ms |
19404 KB |
Output is correct |
50 |
Correct |
336 ms |
19312 KB |
Output is correct |
51 |
Correct |
330 ms |
19332 KB |
Output is correct |
52 |
Correct |
349 ms |
19304 KB |
Output is correct |
53 |
Correct |
344 ms |
19356 KB |
Output is correct |
54 |
Correct |
342 ms |
19436 KB |
Output is correct |
55 |
Correct |
345 ms |
19340 KB |
Output is correct |
56 |
Correct |
336 ms |
19452 KB |
Output is correct |
57 |
Correct |
336 ms |
19224 KB |
Output is correct |
58 |
Correct |
349 ms |
19396 KB |
Output is correct |
59 |
Correct |
333 ms |
19348 KB |
Output is correct |
60 |
Correct |
356 ms |
19344 KB |
Output is correct |
61 |
Correct |
373 ms |
19380 KB |
Output is correct |
62 |
Correct |
335 ms |
19284 KB |
Output is correct |
63 |
Correct |
335 ms |
19256 KB |
Output is correct |
64 |
Correct |
339 ms |
19552 KB |
Output is correct |
65 |
Correct |
346 ms |
19560 KB |
Output is correct |
66 |
Correct |
356 ms |
19460 KB |
Output is correct |
67 |
Correct |
340 ms |
19548 KB |
Output is correct |
68 |
Correct |
347 ms |
19508 KB |
Output is correct |
69 |
Correct |
370 ms |
19528 KB |
Output is correct |
70 |
Correct |
372 ms |
19548 KB |
Output is correct |
71 |
Correct |
370 ms |
19652 KB |
Output is correct |
72 |
Correct |
340 ms |
19528 KB |
Output is correct |
73 |
Correct |
390 ms |
19556 KB |
Output is correct |
74 |
Correct |
350 ms |
19684 KB |
Output is correct |
75 |
Correct |
337 ms |
19552 KB |
Output is correct |
76 |
Correct |
345 ms |
19528 KB |
Output is correct |
77 |
Correct |
340 ms |
19540 KB |
Output is correct |
78 |
Correct |
372 ms |
19508 KB |
Output is correct |
79 |
Correct |
346 ms |
19564 KB |
Output is correct |
80 |
Correct |
355 ms |
19596 KB |
Output is correct |
81 |
Correct |
343 ms |
19520 KB |
Output is correct |
82 |
Correct |
351 ms |
19652 KB |
Output is correct |
83 |
Correct |
350 ms |
19544 KB |
Output is correct |
84 |
Correct |
374 ms |
19556 KB |
Output is correct |