#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cassert>
using namespace std;
using ll = long long;
const int MAXV = 33;
const ll MOD = 998244353;
ll f[MAXV][MAXV];
ll dp[MAXV][MAXV][MAXV];
int to_int(char c) {
if ('a' <= c && c <= 'z')
return c - 'a';
assert(0);
if ('A' <= c && c <= 'Z')
return c - 'A' + 26;
return c - '0' + 52;
}
void get_edg(vector<string> v) {
for (int p = 0; p < MAXV; ++p) {
for (int q = 0; q < MAXV; ++q) {
f[p][q] = 0;
}
}
sort(v.begin(), v.end());
v.resize(unique(v.begin(), v.end()) - v.begin());
for (size_t i = 0; i < v.size(); ++i) {
int p = to_int(v[i][0]);
int q = to_int(v[i].back());
++f[p][q];
}
}
void get_dp() {
for (int a = 0; a < MAXV; ++a) for (int b = 0; b < MAXV; ++b) for (int c = 0; c < MAXV; ++c) {
if (b < a) {
dp[a][b][c] = dp[b][a][c];
continue;
}
if (c < b) {
dp[a][b][c] = dp[a][c][b];
continue;
}
dp[a][b][c] = 0;
for (int x = 0; x < MAXV; ++x) {
dp[a][b][c] += 1ll * f[a][x] * f[b][x] * f[c][x];
dp[a][b][c] %= MOD;
}
}
}
ll get_ans() {
ll ans = 0;
get_dp();
for (int a = 0; a < MAXV; ++a) for (int b = 0; b < MAXV; ++b) for (int c = 0; c < MAXV; ++c) for (int d = 0; d < MAXV; ++d) {
ll pans = ans;
ans += dp[a][b][c] * dp[a][b][d] % MOD * dp[a][c][d] % MOD * dp[b][c][d] % MOD;
ans %= MOD;
}
return ans;
}
signed main() {
int n;
cin >> n;
vector<vector<string>> vals(11);
for (int i = 0; i < n; ++i) {
string s;
cin >> s;
vals[s.size()].push_back(s);
reverse(s.begin(), s.end());
vals[s.size()].push_back(s);
}
ll ans = 0;
for (int t = 0; t < 11; ++t) {
if (vals[t].empty())
continue;
get_edg(vals[t]);
ans += get_ans();
}
ans %= MOD;
cout << ans << '\n';
}
Compilation message
cubeword.cpp: In function 'll get_ans()':
cubeword.cpp:60:12: warning: unused variable 'pans' [-Wunused-variable]
60 | ll pans = ans;
| ^~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
154 ms |
9400 KB |
Output is correct |
2 |
Correct |
154 ms |
10240 KB |
Output is correct |
3 |
Correct |
150 ms |
10296 KB |
Output is correct |
4 |
Correct |
147 ms |
10304 KB |
Output is correct |
5 |
Correct |
153 ms |
10264 KB |
Output is correct |
6 |
Correct |
146 ms |
10404 KB |
Output is correct |
7 |
Correct |
148 ms |
10208 KB |
Output is correct |
8 |
Correct |
155 ms |
10148 KB |
Output is correct |
9 |
Correct |
153 ms |
10340 KB |
Output is correct |
10 |
Correct |
152 ms |
10300 KB |
Output is correct |
11 |
Correct |
150 ms |
10316 KB |
Output is correct |
12 |
Correct |
150 ms |
10300 KB |
Output is correct |
13 |
Correct |
156 ms |
10224 KB |
Output is correct |
14 |
Correct |
161 ms |
10376 KB |
Output is correct |
15 |
Correct |
162 ms |
10292 KB |
Output is correct |
16 |
Correct |
152 ms |
10340 KB |
Output is correct |
17 |
Correct |
149 ms |
10260 KB |
Output is correct |
18 |
Correct |
152 ms |
10260 KB |
Output is correct |
19 |
Correct |
151 ms |
10212 KB |
Output is correct |
20 |
Correct |
161 ms |
10216 KB |
Output is correct |
21 |
Correct |
153 ms |
10116 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
154 ms |
9400 KB |
Output is correct |
2 |
Correct |
154 ms |
10240 KB |
Output is correct |
3 |
Correct |
150 ms |
10296 KB |
Output is correct |
4 |
Correct |
147 ms |
10304 KB |
Output is correct |
5 |
Correct |
153 ms |
10264 KB |
Output is correct |
6 |
Correct |
146 ms |
10404 KB |
Output is correct |
7 |
Correct |
148 ms |
10208 KB |
Output is correct |
8 |
Correct |
155 ms |
10148 KB |
Output is correct |
9 |
Correct |
153 ms |
10340 KB |
Output is correct |
10 |
Correct |
152 ms |
10300 KB |
Output is correct |
11 |
Correct |
150 ms |
10316 KB |
Output is correct |
12 |
Correct |
150 ms |
10300 KB |
Output is correct |
13 |
Correct |
156 ms |
10224 KB |
Output is correct |
14 |
Correct |
161 ms |
10376 KB |
Output is correct |
15 |
Correct |
162 ms |
10292 KB |
Output is correct |
16 |
Correct |
152 ms |
10340 KB |
Output is correct |
17 |
Correct |
149 ms |
10260 KB |
Output is correct |
18 |
Correct |
152 ms |
10260 KB |
Output is correct |
19 |
Correct |
151 ms |
10212 KB |
Output is correct |
20 |
Correct |
161 ms |
10216 KB |
Output is correct |
21 |
Correct |
153 ms |
10116 KB |
Output is correct |
22 |
Correct |
148 ms |
8872 KB |
Output is correct |
23 |
Correct |
149 ms |
8796 KB |
Output is correct |
24 |
Correct |
158 ms |
8936 KB |
Output is correct |
25 |
Correct |
149 ms |
8792 KB |
Output is correct |
26 |
Correct |
149 ms |
8980 KB |
Output is correct |
27 |
Correct |
169 ms |
8876 KB |
Output is correct |
28 |
Correct |
147 ms |
8840 KB |
Output is correct |
29 |
Correct |
147 ms |
8840 KB |
Output is correct |
30 |
Correct |
166 ms |
8820 KB |
Output is correct |
31 |
Correct |
172 ms |
8920 KB |
Output is correct |
32 |
Correct |
148 ms |
8864 KB |
Output is correct |
33 |
Correct |
153 ms |
8908 KB |
Output is correct |
34 |
Correct |
185 ms |
8904 KB |
Output is correct |
35 |
Correct |
148 ms |
8892 KB |
Output is correct |
36 |
Correct |
145 ms |
8684 KB |
Output is correct |
37 |
Correct |
149 ms |
8820 KB |
Output is correct |
38 |
Correct |
152 ms |
8868 KB |
Output is correct |
39 |
Correct |
152 ms |
8800 KB |
Output is correct |
40 |
Correct |
149 ms |
8684 KB |
Output is correct |
41 |
Correct |
146 ms |
8900 KB |
Output is correct |
42 |
Correct |
147 ms |
8904 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
154 ms |
9400 KB |
Output is correct |
2 |
Correct |
154 ms |
10240 KB |
Output is correct |
3 |
Correct |
150 ms |
10296 KB |
Output is correct |
4 |
Correct |
147 ms |
10304 KB |
Output is correct |
5 |
Correct |
153 ms |
10264 KB |
Output is correct |
6 |
Correct |
146 ms |
10404 KB |
Output is correct |
7 |
Correct |
148 ms |
10208 KB |
Output is correct |
8 |
Correct |
155 ms |
10148 KB |
Output is correct |
9 |
Correct |
153 ms |
10340 KB |
Output is correct |
10 |
Correct |
152 ms |
10300 KB |
Output is correct |
11 |
Correct |
150 ms |
10316 KB |
Output is correct |
12 |
Correct |
150 ms |
10300 KB |
Output is correct |
13 |
Correct |
156 ms |
10224 KB |
Output is correct |
14 |
Correct |
161 ms |
10376 KB |
Output is correct |
15 |
Correct |
162 ms |
10292 KB |
Output is correct |
16 |
Correct |
152 ms |
10340 KB |
Output is correct |
17 |
Correct |
149 ms |
10260 KB |
Output is correct |
18 |
Correct |
152 ms |
10260 KB |
Output is correct |
19 |
Correct |
151 ms |
10212 KB |
Output is correct |
20 |
Correct |
161 ms |
10216 KB |
Output is correct |
21 |
Correct |
153 ms |
10116 KB |
Output is correct |
22 |
Correct |
148 ms |
8872 KB |
Output is correct |
23 |
Correct |
149 ms |
8796 KB |
Output is correct |
24 |
Correct |
158 ms |
8936 KB |
Output is correct |
25 |
Correct |
149 ms |
8792 KB |
Output is correct |
26 |
Correct |
149 ms |
8980 KB |
Output is correct |
27 |
Correct |
169 ms |
8876 KB |
Output is correct |
28 |
Correct |
147 ms |
8840 KB |
Output is correct |
29 |
Correct |
147 ms |
8840 KB |
Output is correct |
30 |
Correct |
166 ms |
8820 KB |
Output is correct |
31 |
Correct |
172 ms |
8920 KB |
Output is correct |
32 |
Correct |
148 ms |
8864 KB |
Output is correct |
33 |
Correct |
153 ms |
8908 KB |
Output is correct |
34 |
Correct |
185 ms |
8904 KB |
Output is correct |
35 |
Correct |
148 ms |
8892 KB |
Output is correct |
36 |
Correct |
145 ms |
8684 KB |
Output is correct |
37 |
Correct |
149 ms |
8820 KB |
Output is correct |
38 |
Correct |
152 ms |
8868 KB |
Output is correct |
39 |
Correct |
152 ms |
8800 KB |
Output is correct |
40 |
Correct |
149 ms |
8684 KB |
Output is correct |
41 |
Correct |
146 ms |
8900 KB |
Output is correct |
42 |
Correct |
147 ms |
8904 KB |
Output is correct |
43 |
Runtime error |
43 ms |
15552 KB |
Execution killed with signal 6 |
44 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
154 ms |
9400 KB |
Output is correct |
2 |
Correct |
154 ms |
10240 KB |
Output is correct |
3 |
Correct |
150 ms |
10296 KB |
Output is correct |
4 |
Correct |
147 ms |
10304 KB |
Output is correct |
5 |
Correct |
153 ms |
10264 KB |
Output is correct |
6 |
Correct |
146 ms |
10404 KB |
Output is correct |
7 |
Correct |
148 ms |
10208 KB |
Output is correct |
8 |
Correct |
155 ms |
10148 KB |
Output is correct |
9 |
Correct |
153 ms |
10340 KB |
Output is correct |
10 |
Correct |
152 ms |
10300 KB |
Output is correct |
11 |
Correct |
150 ms |
10316 KB |
Output is correct |
12 |
Correct |
150 ms |
10300 KB |
Output is correct |
13 |
Correct |
156 ms |
10224 KB |
Output is correct |
14 |
Correct |
161 ms |
10376 KB |
Output is correct |
15 |
Correct |
162 ms |
10292 KB |
Output is correct |
16 |
Correct |
152 ms |
10340 KB |
Output is correct |
17 |
Correct |
149 ms |
10260 KB |
Output is correct |
18 |
Correct |
152 ms |
10260 KB |
Output is correct |
19 |
Correct |
151 ms |
10212 KB |
Output is correct |
20 |
Correct |
161 ms |
10216 KB |
Output is correct |
21 |
Correct |
153 ms |
10116 KB |
Output is correct |
22 |
Correct |
148 ms |
8872 KB |
Output is correct |
23 |
Correct |
149 ms |
8796 KB |
Output is correct |
24 |
Correct |
158 ms |
8936 KB |
Output is correct |
25 |
Correct |
149 ms |
8792 KB |
Output is correct |
26 |
Correct |
149 ms |
8980 KB |
Output is correct |
27 |
Correct |
169 ms |
8876 KB |
Output is correct |
28 |
Correct |
147 ms |
8840 KB |
Output is correct |
29 |
Correct |
147 ms |
8840 KB |
Output is correct |
30 |
Correct |
166 ms |
8820 KB |
Output is correct |
31 |
Correct |
172 ms |
8920 KB |
Output is correct |
32 |
Correct |
148 ms |
8864 KB |
Output is correct |
33 |
Correct |
153 ms |
8908 KB |
Output is correct |
34 |
Correct |
185 ms |
8904 KB |
Output is correct |
35 |
Correct |
148 ms |
8892 KB |
Output is correct |
36 |
Correct |
145 ms |
8684 KB |
Output is correct |
37 |
Correct |
149 ms |
8820 KB |
Output is correct |
38 |
Correct |
152 ms |
8868 KB |
Output is correct |
39 |
Correct |
152 ms |
8800 KB |
Output is correct |
40 |
Correct |
149 ms |
8684 KB |
Output is correct |
41 |
Correct |
146 ms |
8900 KB |
Output is correct |
42 |
Correct |
147 ms |
8904 KB |
Output is correct |
43 |
Runtime error |
43 ms |
15552 KB |
Execution killed with signal 6 |
44 |
Halted |
0 ms |
0 KB |
- |