#include<bits/stdc++.h>
#define pb push_back
#define ii pair<int,int>
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define INF 100000000000000000
#define modulo 1000000007
#define mod 998244353
//#define int long long int
using namespace std;
const int k = 32;
int dp[k][k][k];
int cnt[k][k];
map<char, int> ptr;
void clear(){
for(int a = 0; a < k; a++){
for(int b = 0; b < k; b++){
for(int c = 0; c < k; c++){
dp[a][b][c] = 0;
}
}
}
}
int solve(vector<vector<int>>& cnt){
clear();
for(int a = 0; a < k; a++){
for(int b = 0; b < k; b++){
for(int f = 0; f < k; f++){
for(int d = 0; d < k; d++){
dp[a][f][d] = (1ll * dp[a][f][d] + 1ll * cnt[b][a] * cnt[b][f] * cnt[b][d]) % mod;
}
}
}
}
int64_t ret = 0;
for(int a = 0; a < k; a++){
for(int f = 0; f < k; f++){
for(int g = 0; g < k; g++){
for(int d = 0; d < k; d++){
ret += 1ll * dp[a][f][d] * dp[d][f][g] % mod * dp[a][f][g] % mod * dp[a][g][d];
ret %= mod;
}
}
}
}
return ret;
}
int32_t main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n;
int64_t ans = 0;
cin >> n;
unordered_set<string> S[11];
vector<string> arr;
for(int i = 0; i < n; i++){
string s;
cin >> s;
S[sz(s)].insert(s);
reverse(all(s));
S[sz(s)].insert(s);
}
for(char i = 'a'; i <= 'p'; i++) ptr[i] = 0;
for(char i = 'A'; i <= 'P'; i++) ptr[i] = 0;
int ind = 0;
for(auto& p : ptr){
p.second = ind++;
}
for(int i = 3; i <= 10; i++){
if(S[i].empty()) continue;
vector<vector<int> > cnt(k, vector<int>(k, 0));
for(auto p : S[i]){
cnt[ptr[p[0]]][ptr[p[i - 1]]]++;
}
ans += solve(cnt);
}
cout << ans % mod;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
259 ms |
14504 KB |
Output is correct |
2 |
Correct |
227 ms |
14504 KB |
Output is correct |
3 |
Correct |
236 ms |
14504 KB |
Output is correct |
4 |
Correct |
239 ms |
14608 KB |
Output is correct |
5 |
Correct |
230 ms |
14504 KB |
Output is correct |
6 |
Correct |
227 ms |
14504 KB |
Output is correct |
7 |
Correct |
286 ms |
14424 KB |
Output is correct |
8 |
Correct |
222 ms |
14504 KB |
Output is correct |
9 |
Correct |
236 ms |
14500 KB |
Output is correct |
10 |
Correct |
247 ms |
14632 KB |
Output is correct |
11 |
Correct |
258 ms |
14504 KB |
Output is correct |
12 |
Correct |
228 ms |
14508 KB |
Output is correct |
13 |
Correct |
250 ms |
14504 KB |
Output is correct |
14 |
Correct |
222 ms |
14480 KB |
Output is correct |
15 |
Correct |
232 ms |
14436 KB |
Output is correct |
16 |
Correct |
228 ms |
14504 KB |
Output is correct |
17 |
Correct |
238 ms |
14504 KB |
Output is correct |
18 |
Correct |
287 ms |
14504 KB |
Output is correct |
19 |
Correct |
267 ms |
14504 KB |
Output is correct |
20 |
Correct |
232 ms |
14632 KB |
Output is correct |
21 |
Correct |
236 ms |
14504 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
259 ms |
14504 KB |
Output is correct |
2 |
Correct |
227 ms |
14504 KB |
Output is correct |
3 |
Correct |
236 ms |
14504 KB |
Output is correct |
4 |
Correct |
239 ms |
14608 KB |
Output is correct |
5 |
Correct |
230 ms |
14504 KB |
Output is correct |
6 |
Correct |
227 ms |
14504 KB |
Output is correct |
7 |
Correct |
286 ms |
14424 KB |
Output is correct |
8 |
Correct |
222 ms |
14504 KB |
Output is correct |
9 |
Correct |
236 ms |
14500 KB |
Output is correct |
10 |
Correct |
247 ms |
14632 KB |
Output is correct |
11 |
Correct |
258 ms |
14504 KB |
Output is correct |
12 |
Correct |
228 ms |
14508 KB |
Output is correct |
13 |
Correct |
250 ms |
14504 KB |
Output is correct |
14 |
Correct |
222 ms |
14480 KB |
Output is correct |
15 |
Correct |
232 ms |
14436 KB |
Output is correct |
16 |
Correct |
228 ms |
14504 KB |
Output is correct |
17 |
Correct |
238 ms |
14504 KB |
Output is correct |
18 |
Correct |
287 ms |
14504 KB |
Output is correct |
19 |
Correct |
267 ms |
14504 KB |
Output is correct |
20 |
Correct |
232 ms |
14632 KB |
Output is correct |
21 |
Correct |
236 ms |
14504 KB |
Output is correct |
22 |
Correct |
209 ms |
14456 KB |
Output is correct |
23 |
Correct |
235 ms |
14456 KB |
Output is correct |
24 |
Correct |
216 ms |
14584 KB |
Output is correct |
25 |
Correct |
221 ms |
14456 KB |
Output is correct |
26 |
Correct |
211 ms |
14456 KB |
Output is correct |
27 |
Correct |
224 ms |
14584 KB |
Output is correct |
28 |
Correct |
219 ms |
14524 KB |
Output is correct |
29 |
Correct |
220 ms |
14456 KB |
Output is correct |
30 |
Correct |
206 ms |
14584 KB |
Output is correct |
31 |
Correct |
220 ms |
14460 KB |
Output is correct |
32 |
Correct |
218 ms |
14456 KB |
Output is correct |
33 |
Correct |
209 ms |
14456 KB |
Output is correct |
34 |
Correct |
249 ms |
14488 KB |
Output is correct |
35 |
Correct |
228 ms |
14584 KB |
Output is correct |
36 |
Correct |
266 ms |
14584 KB |
Output is correct |
37 |
Correct |
275 ms |
14584 KB |
Output is correct |
38 |
Correct |
257 ms |
14456 KB |
Output is correct |
39 |
Correct |
241 ms |
14456 KB |
Output is correct |
40 |
Correct |
239 ms |
14584 KB |
Output is correct |
41 |
Correct |
258 ms |
14456 KB |
Output is correct |
42 |
Correct |
219 ms |
14492 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
259 ms |
14504 KB |
Output is correct |
2 |
Correct |
227 ms |
14504 KB |
Output is correct |
3 |
Correct |
236 ms |
14504 KB |
Output is correct |
4 |
Correct |
239 ms |
14608 KB |
Output is correct |
5 |
Correct |
230 ms |
14504 KB |
Output is correct |
6 |
Correct |
227 ms |
14504 KB |
Output is correct |
7 |
Correct |
286 ms |
14424 KB |
Output is correct |
8 |
Correct |
222 ms |
14504 KB |
Output is correct |
9 |
Correct |
236 ms |
14500 KB |
Output is correct |
10 |
Correct |
247 ms |
14632 KB |
Output is correct |
11 |
Correct |
258 ms |
14504 KB |
Output is correct |
12 |
Correct |
228 ms |
14508 KB |
Output is correct |
13 |
Correct |
250 ms |
14504 KB |
Output is correct |
14 |
Correct |
222 ms |
14480 KB |
Output is correct |
15 |
Correct |
232 ms |
14436 KB |
Output is correct |
16 |
Correct |
228 ms |
14504 KB |
Output is correct |
17 |
Correct |
238 ms |
14504 KB |
Output is correct |
18 |
Correct |
287 ms |
14504 KB |
Output is correct |
19 |
Correct |
267 ms |
14504 KB |
Output is correct |
20 |
Correct |
232 ms |
14632 KB |
Output is correct |
21 |
Correct |
236 ms |
14504 KB |
Output is correct |
22 |
Correct |
209 ms |
14456 KB |
Output is correct |
23 |
Correct |
235 ms |
14456 KB |
Output is correct |
24 |
Correct |
216 ms |
14584 KB |
Output is correct |
25 |
Correct |
221 ms |
14456 KB |
Output is correct |
26 |
Correct |
211 ms |
14456 KB |
Output is correct |
27 |
Correct |
224 ms |
14584 KB |
Output is correct |
28 |
Correct |
219 ms |
14524 KB |
Output is correct |
29 |
Correct |
220 ms |
14456 KB |
Output is correct |
30 |
Correct |
206 ms |
14584 KB |
Output is correct |
31 |
Correct |
220 ms |
14460 KB |
Output is correct |
32 |
Correct |
218 ms |
14456 KB |
Output is correct |
33 |
Correct |
209 ms |
14456 KB |
Output is correct |
34 |
Correct |
249 ms |
14488 KB |
Output is correct |
35 |
Correct |
228 ms |
14584 KB |
Output is correct |
36 |
Correct |
266 ms |
14584 KB |
Output is correct |
37 |
Correct |
275 ms |
14584 KB |
Output is correct |
38 |
Correct |
257 ms |
14456 KB |
Output is correct |
39 |
Correct |
241 ms |
14456 KB |
Output is correct |
40 |
Correct |
239 ms |
14584 KB |
Output is correct |
41 |
Correct |
258 ms |
14456 KB |
Output is correct |
42 |
Correct |
219 ms |
14492 KB |
Output is correct |
43 |
Correct |
227 ms |
14840 KB |
Output is correct |
44 |
Correct |
250 ms |
15480 KB |
Output is correct |
45 |
Correct |
215 ms |
15608 KB |
Output is correct |
46 |
Correct |
238 ms |
15480 KB |
Output is correct |
47 |
Correct |
221 ms |
15608 KB |
Output is correct |
48 |
Correct |
247 ms |
15608 KB |
Output is correct |
49 |
Correct |
221 ms |
15508 KB |
Output is correct |
50 |
Correct |
260 ms |
15480 KB |
Output is correct |
51 |
Correct |
217 ms |
15480 KB |
Output is correct |
52 |
Correct |
214 ms |
15608 KB |
Output is correct |
53 |
Correct |
274 ms |
15480 KB |
Output is correct |
54 |
Correct |
221 ms |
15480 KB |
Output is correct |
55 |
Correct |
246 ms |
15596 KB |
Output is correct |
56 |
Correct |
274 ms |
15480 KB |
Output is correct |
57 |
Correct |
207 ms |
15480 KB |
Output is correct |
58 |
Correct |
220 ms |
15548 KB |
Output is correct |
59 |
Correct |
198 ms |
15480 KB |
Output is correct |
60 |
Correct |
203 ms |
15480 KB |
Output is correct |
61 |
Correct |
202 ms |
15480 KB |
Output is correct |
62 |
Correct |
216 ms |
15480 KB |
Output is correct |
63 |
Correct |
214 ms |
15480 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
259 ms |
14504 KB |
Output is correct |
2 |
Correct |
227 ms |
14504 KB |
Output is correct |
3 |
Correct |
236 ms |
14504 KB |
Output is correct |
4 |
Correct |
239 ms |
14608 KB |
Output is correct |
5 |
Correct |
230 ms |
14504 KB |
Output is correct |
6 |
Correct |
227 ms |
14504 KB |
Output is correct |
7 |
Correct |
286 ms |
14424 KB |
Output is correct |
8 |
Correct |
222 ms |
14504 KB |
Output is correct |
9 |
Correct |
236 ms |
14500 KB |
Output is correct |
10 |
Correct |
247 ms |
14632 KB |
Output is correct |
11 |
Correct |
258 ms |
14504 KB |
Output is correct |
12 |
Correct |
228 ms |
14508 KB |
Output is correct |
13 |
Correct |
250 ms |
14504 KB |
Output is correct |
14 |
Correct |
222 ms |
14480 KB |
Output is correct |
15 |
Correct |
232 ms |
14436 KB |
Output is correct |
16 |
Correct |
228 ms |
14504 KB |
Output is correct |
17 |
Correct |
238 ms |
14504 KB |
Output is correct |
18 |
Correct |
287 ms |
14504 KB |
Output is correct |
19 |
Correct |
267 ms |
14504 KB |
Output is correct |
20 |
Correct |
232 ms |
14632 KB |
Output is correct |
21 |
Correct |
236 ms |
14504 KB |
Output is correct |
22 |
Correct |
209 ms |
14456 KB |
Output is correct |
23 |
Correct |
235 ms |
14456 KB |
Output is correct |
24 |
Correct |
216 ms |
14584 KB |
Output is correct |
25 |
Correct |
221 ms |
14456 KB |
Output is correct |
26 |
Correct |
211 ms |
14456 KB |
Output is correct |
27 |
Correct |
224 ms |
14584 KB |
Output is correct |
28 |
Correct |
219 ms |
14524 KB |
Output is correct |
29 |
Correct |
220 ms |
14456 KB |
Output is correct |
30 |
Correct |
206 ms |
14584 KB |
Output is correct |
31 |
Correct |
220 ms |
14460 KB |
Output is correct |
32 |
Correct |
218 ms |
14456 KB |
Output is correct |
33 |
Correct |
209 ms |
14456 KB |
Output is correct |
34 |
Correct |
249 ms |
14488 KB |
Output is correct |
35 |
Correct |
228 ms |
14584 KB |
Output is correct |
36 |
Correct |
266 ms |
14584 KB |
Output is correct |
37 |
Correct |
275 ms |
14584 KB |
Output is correct |
38 |
Correct |
257 ms |
14456 KB |
Output is correct |
39 |
Correct |
241 ms |
14456 KB |
Output is correct |
40 |
Correct |
239 ms |
14584 KB |
Output is correct |
41 |
Correct |
258 ms |
14456 KB |
Output is correct |
42 |
Correct |
219 ms |
14492 KB |
Output is correct |
43 |
Correct |
227 ms |
14840 KB |
Output is correct |
44 |
Correct |
250 ms |
15480 KB |
Output is correct |
45 |
Correct |
215 ms |
15608 KB |
Output is correct |
46 |
Correct |
238 ms |
15480 KB |
Output is correct |
47 |
Correct |
221 ms |
15608 KB |
Output is correct |
48 |
Correct |
247 ms |
15608 KB |
Output is correct |
49 |
Correct |
221 ms |
15508 KB |
Output is correct |
50 |
Correct |
260 ms |
15480 KB |
Output is correct |
51 |
Correct |
217 ms |
15480 KB |
Output is correct |
52 |
Correct |
214 ms |
15608 KB |
Output is correct |
53 |
Correct |
274 ms |
15480 KB |
Output is correct |
54 |
Correct |
221 ms |
15480 KB |
Output is correct |
55 |
Correct |
246 ms |
15596 KB |
Output is correct |
56 |
Correct |
274 ms |
15480 KB |
Output is correct |
57 |
Correct |
207 ms |
15480 KB |
Output is correct |
58 |
Correct |
220 ms |
15548 KB |
Output is correct |
59 |
Correct |
198 ms |
15480 KB |
Output is correct |
60 |
Correct |
203 ms |
15480 KB |
Output is correct |
61 |
Correct |
202 ms |
15480 KB |
Output is correct |
62 |
Correct |
216 ms |
15480 KB |
Output is correct |
63 |
Correct |
214 ms |
15480 KB |
Output is correct |
64 |
Incorrect |
209 ms |
15676 KB |
Output isn't correct |
65 |
Halted |
0 ms |
0 KB |
- |