#include <bits/stdc++.h>
using namespace std;
const int MOD = 998244353;
const int MK = 32;
using vi = vector<int>;
using ll = long long;
int id2(char c) {
if(c >= 'a' && c <= 'z') return c - 'a';
if(c >= 'A' && c <= 'Z') return c - 'A' + 26;
return c - '0' + 52;
}
int id(char c) {
if(c >= 'a' && c <= 'p') return c - 'a';
if(c >= 'A' && c <= 'P') return c - 'A' + 16;
}
int solve(vector<string> V) {
if(V.empty()) return 0;
set<string> S;
for (auto it : V) {
S.insert(it);
string s2 = it;
reverse(s2.begin(), s2.end());
S.insert(s2);
}
array<array<int, MK>, MK> Fr;
for (int i = 0; i < MK; ++i)
for (int j = 0; j < MK; ++j)
Fr[i][j] = 0;
for (auto it : S) {
int a = id(it[0]), b= id(it.back());
++Fr[a][b];
}
array<array<array<int, MK>, MK>, MK> u, v;
for(int i = 0; i < MK; ++i)
for(int j = 0; j < MK; ++j)
for(int k = 0; k < MK; ++k)
u[i][j][k] = v[i][j][k] = 0;
for(int i = 0; i < MK; ++i)
for(int j = 0; j < MK; ++j)
for(int k = 0; k < MK; ++k) {
for(int w = 0; w < MK; ++w) {
v[i][j][k] = (v[i][j][k]
+ 1ll * Fr[i][w] * Fr[j][w] % MOD * Fr[k][w] % MOD) % MOD;
}
}
for(int i = 0; i < MK; ++i)
for(int j = 0; j < MK; ++j)
for(int k = 0; k < MK; ++k)
u[i][j][k] = 1ll * Fr[i][k] * Fr[j][k] % MOD;
ll re = 0;
for(int i = 0; i < MK; ++i)
for(int j = 0; j < MK; ++j)
for(int k = 0; k < MK; ++k)
for(int w = 0; w < MK; ++w) {
/// (v[i,j] \cdot u[k, w]) * (v[k, w] \cdot u[i, j])
ll v1 = 0, v2 = 0;
for(int a = 0; a < MK; ++a)
v1 = (v1 + 1ll * v[i][j][a] * u[k][w][a]);
for(int a = 0; a < MK; ++a)
v2 = (v2 + 1ll * v[k][w][a] * u[i][j][a]);
v1 %= MOD;
v2 %= MOD;
ll cre = v1 * v2 % MOD * Fr[i][k] % MOD * Fr[j][w] % MOD;
re = (re + cre) % MOD;
}
return (int)re;
}
int main() {
const int MLEN = 10;
vector<vector<string> > V(MLEN + 1);
int n;
cin >> n;
for (int i = 0; i < n; ++i) {
string s;
cin >> s;
V[s.size()].push_back(s);
}
int re = 0;
for (int i = 0; i <= MLEN; ++i) {
re = (re + solve(V[i])) % MOD;
}
cout << re << "\n";
return 0;
}
Compilation message
cubeword.cpp: In function 'int id(char)':
cubeword.cpp:18:1: warning: control reaches end of non-void function [-Wreturn-type]
18 | }
| ^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
540 ms |
8184 KB |
Output is correct |
2 |
Correct |
551 ms |
8176 KB |
Output is correct |
3 |
Correct |
539 ms |
8196 KB |
Output is correct |
4 |
Correct |
555 ms |
8168 KB |
Output is correct |
5 |
Correct |
534 ms |
8136 KB |
Output is correct |
6 |
Correct |
514 ms |
8164 KB |
Output is correct |
7 |
Correct |
545 ms |
8116 KB |
Output is correct |
8 |
Correct |
542 ms |
8168 KB |
Output is correct |
9 |
Correct |
532 ms |
8272 KB |
Output is correct |
10 |
Correct |
513 ms |
8312 KB |
Output is correct |
11 |
Correct |
549 ms |
8172 KB |
Output is correct |
12 |
Correct |
516 ms |
8252 KB |
Output is correct |
13 |
Correct |
499 ms |
8144 KB |
Output is correct |
14 |
Correct |
525 ms |
8096 KB |
Output is correct |
15 |
Correct |
511 ms |
8124 KB |
Output is correct |
16 |
Correct |
524 ms |
8124 KB |
Output is correct |
17 |
Correct |
554 ms |
8380 KB |
Output is correct |
18 |
Correct |
517 ms |
8120 KB |
Output is correct |
19 |
Correct |
501 ms |
8164 KB |
Output is correct |
20 |
Correct |
549 ms |
8388 KB |
Output is correct |
21 |
Correct |
523 ms |
8272 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
540 ms |
8184 KB |
Output is correct |
2 |
Correct |
551 ms |
8176 KB |
Output is correct |
3 |
Correct |
539 ms |
8196 KB |
Output is correct |
4 |
Correct |
555 ms |
8168 KB |
Output is correct |
5 |
Correct |
534 ms |
8136 KB |
Output is correct |
6 |
Correct |
514 ms |
8164 KB |
Output is correct |
7 |
Correct |
545 ms |
8116 KB |
Output is correct |
8 |
Correct |
542 ms |
8168 KB |
Output is correct |
9 |
Correct |
532 ms |
8272 KB |
Output is correct |
10 |
Correct |
513 ms |
8312 KB |
Output is correct |
11 |
Correct |
549 ms |
8172 KB |
Output is correct |
12 |
Correct |
516 ms |
8252 KB |
Output is correct |
13 |
Correct |
499 ms |
8144 KB |
Output is correct |
14 |
Correct |
525 ms |
8096 KB |
Output is correct |
15 |
Correct |
511 ms |
8124 KB |
Output is correct |
16 |
Correct |
524 ms |
8124 KB |
Output is correct |
17 |
Correct |
554 ms |
8380 KB |
Output is correct |
18 |
Correct |
517 ms |
8120 KB |
Output is correct |
19 |
Correct |
501 ms |
8164 KB |
Output is correct |
20 |
Correct |
549 ms |
8388 KB |
Output is correct |
21 |
Correct |
523 ms |
8272 KB |
Output is correct |
22 |
Correct |
531 ms |
7048 KB |
Output is correct |
23 |
Correct |
543 ms |
7192 KB |
Output is correct |
24 |
Correct |
580 ms |
7128 KB |
Output is correct |
25 |
Correct |
507 ms |
7176 KB |
Output is correct |
26 |
Correct |
556 ms |
7192 KB |
Output is correct |
27 |
Correct |
562 ms |
7144 KB |
Output is correct |
28 |
Correct |
496 ms |
7244 KB |
Output is correct |
29 |
Correct |
532 ms |
7316 KB |
Output is correct |
30 |
Correct |
510 ms |
7148 KB |
Output is correct |
31 |
Correct |
496 ms |
7224 KB |
Output is correct |
32 |
Correct |
544 ms |
7236 KB |
Output is correct |
33 |
Correct |
512 ms |
7264 KB |
Output is correct |
34 |
Correct |
508 ms |
7048 KB |
Output is correct |
35 |
Correct |
506 ms |
7172 KB |
Output is correct |
36 |
Correct |
541 ms |
7140 KB |
Output is correct |
37 |
Correct |
525 ms |
7152 KB |
Output is correct |
38 |
Correct |
531 ms |
7232 KB |
Output is correct |
39 |
Correct |
548 ms |
6996 KB |
Output is correct |
40 |
Correct |
580 ms |
7200 KB |
Output is correct |
41 |
Correct |
570 ms |
7136 KB |
Output is correct |
42 |
Correct |
527 ms |
7200 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
540 ms |
8184 KB |
Output is correct |
2 |
Correct |
551 ms |
8176 KB |
Output is correct |
3 |
Correct |
539 ms |
8196 KB |
Output is correct |
4 |
Correct |
555 ms |
8168 KB |
Output is correct |
5 |
Correct |
534 ms |
8136 KB |
Output is correct |
6 |
Correct |
514 ms |
8164 KB |
Output is correct |
7 |
Correct |
545 ms |
8116 KB |
Output is correct |
8 |
Correct |
542 ms |
8168 KB |
Output is correct |
9 |
Correct |
532 ms |
8272 KB |
Output is correct |
10 |
Correct |
513 ms |
8312 KB |
Output is correct |
11 |
Correct |
549 ms |
8172 KB |
Output is correct |
12 |
Correct |
516 ms |
8252 KB |
Output is correct |
13 |
Correct |
499 ms |
8144 KB |
Output is correct |
14 |
Correct |
525 ms |
8096 KB |
Output is correct |
15 |
Correct |
511 ms |
8124 KB |
Output is correct |
16 |
Correct |
524 ms |
8124 KB |
Output is correct |
17 |
Correct |
554 ms |
8380 KB |
Output is correct |
18 |
Correct |
517 ms |
8120 KB |
Output is correct |
19 |
Correct |
501 ms |
8164 KB |
Output is correct |
20 |
Correct |
549 ms |
8388 KB |
Output is correct |
21 |
Correct |
523 ms |
8272 KB |
Output is correct |
22 |
Correct |
531 ms |
7048 KB |
Output is correct |
23 |
Correct |
543 ms |
7192 KB |
Output is correct |
24 |
Correct |
580 ms |
7128 KB |
Output is correct |
25 |
Correct |
507 ms |
7176 KB |
Output is correct |
26 |
Correct |
556 ms |
7192 KB |
Output is correct |
27 |
Correct |
562 ms |
7144 KB |
Output is correct |
28 |
Correct |
496 ms |
7244 KB |
Output is correct |
29 |
Correct |
532 ms |
7316 KB |
Output is correct |
30 |
Correct |
510 ms |
7148 KB |
Output is correct |
31 |
Correct |
496 ms |
7224 KB |
Output is correct |
32 |
Correct |
544 ms |
7236 KB |
Output is correct |
33 |
Correct |
512 ms |
7264 KB |
Output is correct |
34 |
Correct |
508 ms |
7048 KB |
Output is correct |
35 |
Correct |
506 ms |
7172 KB |
Output is correct |
36 |
Correct |
541 ms |
7140 KB |
Output is correct |
37 |
Correct |
525 ms |
7152 KB |
Output is correct |
38 |
Correct |
531 ms |
7232 KB |
Output is correct |
39 |
Correct |
548 ms |
6996 KB |
Output is correct |
40 |
Correct |
580 ms |
7200 KB |
Output is correct |
41 |
Correct |
570 ms |
7136 KB |
Output is correct |
42 |
Correct |
527 ms |
7200 KB |
Output is correct |
43 |
Correct |
507 ms |
7096 KB |
Output is correct |
44 |
Correct |
519 ms |
7180 KB |
Output is correct |
45 |
Correct |
540 ms |
6884 KB |
Output is correct |
46 |
Correct |
550 ms |
6800 KB |
Output is correct |
47 |
Correct |
541 ms |
6924 KB |
Output is correct |
48 |
Correct |
539 ms |
6964 KB |
Output is correct |
49 |
Correct |
508 ms |
6892 KB |
Output is correct |
50 |
Correct |
573 ms |
6940 KB |
Output is correct |
51 |
Correct |
546 ms |
6868 KB |
Output is correct |
52 |
Correct |
527 ms |
7132 KB |
Output is correct |
53 |
Correct |
532 ms |
7128 KB |
Output is correct |
54 |
Correct |
539 ms |
7004 KB |
Output is correct |
55 |
Correct |
502 ms |
6816 KB |
Output is correct |
56 |
Correct |
534 ms |
7112 KB |
Output is correct |
57 |
Correct |
573 ms |
6992 KB |
Output is correct |
58 |
Correct |
535 ms |
6820 KB |
Output is correct |
59 |
Correct |
582 ms |
6988 KB |
Output is correct |
60 |
Correct |
538 ms |
7004 KB |
Output is correct |
61 |
Correct |
543 ms |
6984 KB |
Output is correct |
62 |
Correct |
535 ms |
6988 KB |
Output is correct |
63 |
Correct |
571 ms |
6812 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
540 ms |
8184 KB |
Output is correct |
2 |
Correct |
551 ms |
8176 KB |
Output is correct |
3 |
Correct |
539 ms |
8196 KB |
Output is correct |
4 |
Correct |
555 ms |
8168 KB |
Output is correct |
5 |
Correct |
534 ms |
8136 KB |
Output is correct |
6 |
Correct |
514 ms |
8164 KB |
Output is correct |
7 |
Correct |
545 ms |
8116 KB |
Output is correct |
8 |
Correct |
542 ms |
8168 KB |
Output is correct |
9 |
Correct |
532 ms |
8272 KB |
Output is correct |
10 |
Correct |
513 ms |
8312 KB |
Output is correct |
11 |
Correct |
549 ms |
8172 KB |
Output is correct |
12 |
Correct |
516 ms |
8252 KB |
Output is correct |
13 |
Correct |
499 ms |
8144 KB |
Output is correct |
14 |
Correct |
525 ms |
8096 KB |
Output is correct |
15 |
Correct |
511 ms |
8124 KB |
Output is correct |
16 |
Correct |
524 ms |
8124 KB |
Output is correct |
17 |
Correct |
554 ms |
8380 KB |
Output is correct |
18 |
Correct |
517 ms |
8120 KB |
Output is correct |
19 |
Correct |
501 ms |
8164 KB |
Output is correct |
20 |
Correct |
549 ms |
8388 KB |
Output is correct |
21 |
Correct |
523 ms |
8272 KB |
Output is correct |
22 |
Correct |
531 ms |
7048 KB |
Output is correct |
23 |
Correct |
543 ms |
7192 KB |
Output is correct |
24 |
Correct |
580 ms |
7128 KB |
Output is correct |
25 |
Correct |
507 ms |
7176 KB |
Output is correct |
26 |
Correct |
556 ms |
7192 KB |
Output is correct |
27 |
Correct |
562 ms |
7144 KB |
Output is correct |
28 |
Correct |
496 ms |
7244 KB |
Output is correct |
29 |
Correct |
532 ms |
7316 KB |
Output is correct |
30 |
Correct |
510 ms |
7148 KB |
Output is correct |
31 |
Correct |
496 ms |
7224 KB |
Output is correct |
32 |
Correct |
544 ms |
7236 KB |
Output is correct |
33 |
Correct |
512 ms |
7264 KB |
Output is correct |
34 |
Correct |
508 ms |
7048 KB |
Output is correct |
35 |
Correct |
506 ms |
7172 KB |
Output is correct |
36 |
Correct |
541 ms |
7140 KB |
Output is correct |
37 |
Correct |
525 ms |
7152 KB |
Output is correct |
38 |
Correct |
531 ms |
7232 KB |
Output is correct |
39 |
Correct |
548 ms |
6996 KB |
Output is correct |
40 |
Correct |
580 ms |
7200 KB |
Output is correct |
41 |
Correct |
570 ms |
7136 KB |
Output is correct |
42 |
Correct |
527 ms |
7200 KB |
Output is correct |
43 |
Correct |
507 ms |
7096 KB |
Output is correct |
44 |
Correct |
519 ms |
7180 KB |
Output is correct |
45 |
Correct |
540 ms |
6884 KB |
Output is correct |
46 |
Correct |
550 ms |
6800 KB |
Output is correct |
47 |
Correct |
541 ms |
6924 KB |
Output is correct |
48 |
Correct |
539 ms |
6964 KB |
Output is correct |
49 |
Correct |
508 ms |
6892 KB |
Output is correct |
50 |
Correct |
573 ms |
6940 KB |
Output is correct |
51 |
Correct |
546 ms |
6868 KB |
Output is correct |
52 |
Correct |
527 ms |
7132 KB |
Output is correct |
53 |
Correct |
532 ms |
7128 KB |
Output is correct |
54 |
Correct |
539 ms |
7004 KB |
Output is correct |
55 |
Correct |
502 ms |
6816 KB |
Output is correct |
56 |
Correct |
534 ms |
7112 KB |
Output is correct |
57 |
Correct |
573 ms |
6992 KB |
Output is correct |
58 |
Correct |
535 ms |
6820 KB |
Output is correct |
59 |
Correct |
582 ms |
6988 KB |
Output is correct |
60 |
Correct |
538 ms |
7004 KB |
Output is correct |
61 |
Correct |
543 ms |
6984 KB |
Output is correct |
62 |
Correct |
535 ms |
6988 KB |
Output is correct |
63 |
Correct |
571 ms |
6812 KB |
Output is correct |
64 |
Runtime error |
30 ms |
12772 KB |
Execution killed with signal 11 |
65 |
Halted |
0 ms |
0 KB |
- |