#include <bits/stdc++.h>
using namespace std;
constexpr int maxn = 6, 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 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);
}
}
vector<array<int,3>> triad;
for(int a = 0; a < maxn; a++)
for(int b = 0; b < maxn; b++)
for(int c = 0; c < maxn; c++)
triad.push_back({a, b, c});
for(int sz = 3; sz <= 10; sz++) {
for(auto [a, b, c] : triad)
for(int x = 0; x < maxn; x++)
add(value_triad[sz][a][b][c], 1ll * edge[sz][x][a] * edge[sz][x][b] * edge[sz][x][c] % mod);
for(auto [a1, b1, c1] : triad) for(auto [a2, b2, c2] : triad) {
long long aq = 1ll * value_triad[sz][a1][b1][c1] * value_triad[sz][a2][b2][c2] % mod;
aq *= 1ll * edge[sz][a1][b2] * edge[sz][a1][c2] % mod; aq %= mod;
aq *= 1ll * edge[sz][b1][a2] * edge[sz][b1][c2] % mod; aq %= mod;
aq *= 1ll * edge[sz][c1][a2] * edge[sz][c1][b2] % mod; aq %= mod;
add(ans, aq);
}
}
printf("%d\n", ans);
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
193 ms |
14884 KB |
Output is correct |
2 |
Correct |
188 ms |
15560 KB |
Output is correct |
3 |
Correct |
195 ms |
15564 KB |
Output is correct |
4 |
Correct |
199 ms |
15720 KB |
Output is correct |
5 |
Correct |
182 ms |
15644 KB |
Output is correct |
6 |
Correct |
182 ms |
15644 KB |
Output is correct |
7 |
Correct |
188 ms |
15692 KB |
Output is correct |
8 |
Correct |
189 ms |
15760 KB |
Output is correct |
9 |
Correct |
187 ms |
15564 KB |
Output is correct |
10 |
Correct |
181 ms |
15616 KB |
Output is correct |
11 |
Correct |
187 ms |
15592 KB |
Output is correct |
12 |
Correct |
184 ms |
15700 KB |
Output is correct |
13 |
Correct |
182 ms |
15648 KB |
Output is correct |
14 |
Correct |
190 ms |
15556 KB |
Output is correct |
15 |
Correct |
191 ms |
15816 KB |
Output is correct |
16 |
Correct |
182 ms |
15620 KB |
Output is correct |
17 |
Correct |
189 ms |
15652 KB |
Output is correct |
18 |
Correct |
185 ms |
15752 KB |
Output is correct |
19 |
Correct |
187 ms |
15564 KB |
Output is correct |
20 |
Correct |
181 ms |
15556 KB |
Output is correct |
21 |
Correct |
188 ms |
15564 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
193 ms |
14884 KB |
Output is correct |
2 |
Correct |
188 ms |
15560 KB |
Output is correct |
3 |
Correct |
195 ms |
15564 KB |
Output is correct |
4 |
Correct |
199 ms |
15720 KB |
Output is correct |
5 |
Correct |
182 ms |
15644 KB |
Output is correct |
6 |
Correct |
182 ms |
15644 KB |
Output is correct |
7 |
Correct |
188 ms |
15692 KB |
Output is correct |
8 |
Correct |
189 ms |
15760 KB |
Output is correct |
9 |
Correct |
187 ms |
15564 KB |
Output is correct |
10 |
Correct |
181 ms |
15616 KB |
Output is correct |
11 |
Correct |
187 ms |
15592 KB |
Output is correct |
12 |
Correct |
184 ms |
15700 KB |
Output is correct |
13 |
Correct |
182 ms |
15648 KB |
Output is correct |
14 |
Correct |
190 ms |
15556 KB |
Output is correct |
15 |
Correct |
191 ms |
15816 KB |
Output is correct |
16 |
Correct |
182 ms |
15620 KB |
Output is correct |
17 |
Correct |
189 ms |
15652 KB |
Output is correct |
18 |
Correct |
185 ms |
15752 KB |
Output is correct |
19 |
Correct |
187 ms |
15564 KB |
Output is correct |
20 |
Correct |
181 ms |
15556 KB |
Output is correct |
21 |
Correct |
188 ms |
15564 KB |
Output is correct |
22 |
Incorrect |
181 ms |
16220 KB |
Output isn't correct |
23 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
193 ms |
14884 KB |
Output is correct |
2 |
Correct |
188 ms |
15560 KB |
Output is correct |
3 |
Correct |
195 ms |
15564 KB |
Output is correct |
4 |
Correct |
199 ms |
15720 KB |
Output is correct |
5 |
Correct |
182 ms |
15644 KB |
Output is correct |
6 |
Correct |
182 ms |
15644 KB |
Output is correct |
7 |
Correct |
188 ms |
15692 KB |
Output is correct |
8 |
Correct |
189 ms |
15760 KB |
Output is correct |
9 |
Correct |
187 ms |
15564 KB |
Output is correct |
10 |
Correct |
181 ms |
15616 KB |
Output is correct |
11 |
Correct |
187 ms |
15592 KB |
Output is correct |
12 |
Correct |
184 ms |
15700 KB |
Output is correct |
13 |
Correct |
182 ms |
15648 KB |
Output is correct |
14 |
Correct |
190 ms |
15556 KB |
Output is correct |
15 |
Correct |
191 ms |
15816 KB |
Output is correct |
16 |
Correct |
182 ms |
15620 KB |
Output is correct |
17 |
Correct |
189 ms |
15652 KB |
Output is correct |
18 |
Correct |
185 ms |
15752 KB |
Output is correct |
19 |
Correct |
187 ms |
15564 KB |
Output is correct |
20 |
Correct |
181 ms |
15556 KB |
Output is correct |
21 |
Correct |
188 ms |
15564 KB |
Output is correct |
22 |
Incorrect |
181 ms |
16220 KB |
Output isn't correct |
23 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
193 ms |
14884 KB |
Output is correct |
2 |
Correct |
188 ms |
15560 KB |
Output is correct |
3 |
Correct |
195 ms |
15564 KB |
Output is correct |
4 |
Correct |
199 ms |
15720 KB |
Output is correct |
5 |
Correct |
182 ms |
15644 KB |
Output is correct |
6 |
Correct |
182 ms |
15644 KB |
Output is correct |
7 |
Correct |
188 ms |
15692 KB |
Output is correct |
8 |
Correct |
189 ms |
15760 KB |
Output is correct |
9 |
Correct |
187 ms |
15564 KB |
Output is correct |
10 |
Correct |
181 ms |
15616 KB |
Output is correct |
11 |
Correct |
187 ms |
15592 KB |
Output is correct |
12 |
Correct |
184 ms |
15700 KB |
Output is correct |
13 |
Correct |
182 ms |
15648 KB |
Output is correct |
14 |
Correct |
190 ms |
15556 KB |
Output is correct |
15 |
Correct |
191 ms |
15816 KB |
Output is correct |
16 |
Correct |
182 ms |
15620 KB |
Output is correct |
17 |
Correct |
189 ms |
15652 KB |
Output is correct |
18 |
Correct |
185 ms |
15752 KB |
Output is correct |
19 |
Correct |
187 ms |
15564 KB |
Output is correct |
20 |
Correct |
181 ms |
15556 KB |
Output is correct |
21 |
Correct |
188 ms |
15564 KB |
Output is correct |
22 |
Incorrect |
181 ms |
16220 KB |
Output isn't correct |
23 |
Halted |
0 ms |
0 KB |
- |