using namespace std;
#include <iostream>
#include <algorithm>
#include <queue>
#include <stack>
#include <deque>
#include <map>
#include <set>
#include <utility>
#include <memory.h>
#include <vector>
#include <bitset>
typedef pair<int,int> pii;
typedef long long LL;
#define iter(x) x.begin(),x.end()
#define F first
#define S second
#define pb push_back
#define mkp make_pair
#include <climits>
const int maxn = 70,mod = (119 << 23)^1;
int ctoi(char c){
if (c >= 'a' and c <= 'p') return c - 'a';
else if (c >= 'A' and c <= 'P') return c - 'A' + 16;
else if (c > 'p' and c <= 'z') return c - 'p' + 31;
else if (c > 'P' and c <= 'Z') return c - 'P' + 41;
else return c - '0' + 52;
}
LL dp[maxn][maxn][maxn]{};
int main(){
ios_base::sync_with_stdio(false); cin.tie(0);
set <string> st[11];
int n;
cin >> n;
for (int i=0;i<n;++i){
string s; cin >> s;
st[s.size()].insert(s);
reverse(iter(s));
st[s.size()].insert(s);
}
LL ans = 0;
for (int len=3;len<=10;++len) if (!st[len].empty()){
int mx = 0;
LL cnt[maxn][maxn]{};
memset(dp,0,sizeof(dp));
for (string s:st[len]){
++cnt[ctoi(s[0])][ctoi(s.back())];
mx = max(mx,ctoi(s[0]));
}
for (int i=0;i<=mx;++i) for (int j=0;j<=mx;++j) for (int k=0;k<=mx;++k) for (int l=0;l<=mx;++l){
dp[i][j][k] += cnt[i][l] * cnt[j][l] % mod * cnt[k][l] % mod;
dp[i][j][k] %= mod;
}
for (int i=0;i<=mx;++i) for (int j=0;j<=mx;++j) for (int k=0;k<=mx;++k) for (int l=0;l<=mx;++l){
ans += dp[i][j][k] * dp[i][j][l] % mod * dp[i][k][l] % mod * dp[j][k][l];
ans %= mod;
}
}
cout << ans;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
154 ms |
17512 KB |
Output is correct |
2 |
Correct |
156 ms |
17492 KB |
Output is correct |
3 |
Correct |
156 ms |
17504 KB |
Output is correct |
4 |
Correct |
154 ms |
17444 KB |
Output is correct |
5 |
Correct |
152 ms |
17456 KB |
Output is correct |
6 |
Correct |
159 ms |
17504 KB |
Output is correct |
7 |
Correct |
161 ms |
17428 KB |
Output is correct |
8 |
Correct |
157 ms |
17468 KB |
Output is correct |
9 |
Correct |
155 ms |
17540 KB |
Output is correct |
10 |
Correct |
156 ms |
17476 KB |
Output is correct |
11 |
Correct |
161 ms |
17428 KB |
Output is correct |
12 |
Correct |
155 ms |
17456 KB |
Output is correct |
13 |
Correct |
151 ms |
17476 KB |
Output is correct |
14 |
Correct |
156 ms |
17452 KB |
Output is correct |
15 |
Correct |
159 ms |
17408 KB |
Output is correct |
16 |
Correct |
152 ms |
17476 KB |
Output is correct |
17 |
Correct |
156 ms |
17524 KB |
Output is correct |
18 |
Correct |
159 ms |
17576 KB |
Output is correct |
19 |
Correct |
160 ms |
17392 KB |
Output is correct |
20 |
Correct |
159 ms |
17500 KB |
Output is correct |
21 |
Correct |
161 ms |
17556 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
154 ms |
17512 KB |
Output is correct |
2 |
Correct |
156 ms |
17492 KB |
Output is correct |
3 |
Correct |
156 ms |
17504 KB |
Output is correct |
4 |
Correct |
154 ms |
17444 KB |
Output is correct |
5 |
Correct |
152 ms |
17456 KB |
Output is correct |
6 |
Correct |
159 ms |
17504 KB |
Output is correct |
7 |
Correct |
161 ms |
17428 KB |
Output is correct |
8 |
Correct |
157 ms |
17468 KB |
Output is correct |
9 |
Correct |
155 ms |
17540 KB |
Output is correct |
10 |
Correct |
156 ms |
17476 KB |
Output is correct |
11 |
Correct |
161 ms |
17428 KB |
Output is correct |
12 |
Correct |
155 ms |
17456 KB |
Output is correct |
13 |
Correct |
151 ms |
17476 KB |
Output is correct |
14 |
Correct |
156 ms |
17452 KB |
Output is correct |
15 |
Correct |
159 ms |
17408 KB |
Output is correct |
16 |
Correct |
152 ms |
17476 KB |
Output is correct |
17 |
Correct |
156 ms |
17524 KB |
Output is correct |
18 |
Correct |
159 ms |
17576 KB |
Output is correct |
19 |
Correct |
160 ms |
17392 KB |
Output is correct |
20 |
Correct |
159 ms |
17500 KB |
Output is correct |
21 |
Correct |
161 ms |
17556 KB |
Output is correct |
22 |
Correct |
169 ms |
18144 KB |
Output is correct |
23 |
Correct |
174 ms |
18244 KB |
Output is correct |
24 |
Correct |
164 ms |
18116 KB |
Output is correct |
25 |
Correct |
164 ms |
18116 KB |
Output is correct |
26 |
Correct |
169 ms |
18148 KB |
Output is correct |
27 |
Correct |
169 ms |
18152 KB |
Output is correct |
28 |
Correct |
181 ms |
18124 KB |
Output is correct |
29 |
Correct |
167 ms |
18168 KB |
Output is correct |
30 |
Correct |
166 ms |
18156 KB |
Output is correct |
31 |
Correct |
181 ms |
18116 KB |
Output is correct |
32 |
Correct |
165 ms |
18116 KB |
Output is correct |
33 |
Correct |
162 ms |
18124 KB |
Output is correct |
34 |
Correct |
160 ms |
18204 KB |
Output is correct |
35 |
Correct |
175 ms |
18104 KB |
Output is correct |
36 |
Correct |
169 ms |
18164 KB |
Output is correct |
37 |
Correct |
175 ms |
18116 KB |
Output is correct |
38 |
Correct |
178 ms |
18104 KB |
Output is correct |
39 |
Correct |
176 ms |
18144 KB |
Output is correct |
40 |
Correct |
163 ms |
18248 KB |
Output is correct |
41 |
Correct |
183 ms |
18048 KB |
Output is correct |
42 |
Correct |
174 ms |
18092 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
154 ms |
17512 KB |
Output is correct |
2 |
Correct |
156 ms |
17492 KB |
Output is correct |
3 |
Correct |
156 ms |
17504 KB |
Output is correct |
4 |
Correct |
154 ms |
17444 KB |
Output is correct |
5 |
Correct |
152 ms |
17456 KB |
Output is correct |
6 |
Correct |
159 ms |
17504 KB |
Output is correct |
7 |
Correct |
161 ms |
17428 KB |
Output is correct |
8 |
Correct |
157 ms |
17468 KB |
Output is correct |
9 |
Correct |
155 ms |
17540 KB |
Output is correct |
10 |
Correct |
156 ms |
17476 KB |
Output is correct |
11 |
Correct |
161 ms |
17428 KB |
Output is correct |
12 |
Correct |
155 ms |
17456 KB |
Output is correct |
13 |
Correct |
151 ms |
17476 KB |
Output is correct |
14 |
Correct |
156 ms |
17452 KB |
Output is correct |
15 |
Correct |
159 ms |
17408 KB |
Output is correct |
16 |
Correct |
152 ms |
17476 KB |
Output is correct |
17 |
Correct |
156 ms |
17524 KB |
Output is correct |
18 |
Correct |
159 ms |
17576 KB |
Output is correct |
19 |
Correct |
160 ms |
17392 KB |
Output is correct |
20 |
Correct |
159 ms |
17500 KB |
Output is correct |
21 |
Correct |
161 ms |
17556 KB |
Output is correct |
22 |
Correct |
169 ms |
18144 KB |
Output is correct |
23 |
Correct |
174 ms |
18244 KB |
Output is correct |
24 |
Correct |
164 ms |
18116 KB |
Output is correct |
25 |
Correct |
164 ms |
18116 KB |
Output is correct |
26 |
Correct |
169 ms |
18148 KB |
Output is correct |
27 |
Correct |
169 ms |
18152 KB |
Output is correct |
28 |
Correct |
181 ms |
18124 KB |
Output is correct |
29 |
Correct |
167 ms |
18168 KB |
Output is correct |
30 |
Correct |
166 ms |
18156 KB |
Output is correct |
31 |
Correct |
181 ms |
18116 KB |
Output is correct |
32 |
Correct |
165 ms |
18116 KB |
Output is correct |
33 |
Correct |
162 ms |
18124 KB |
Output is correct |
34 |
Correct |
160 ms |
18204 KB |
Output is correct |
35 |
Correct |
175 ms |
18104 KB |
Output is correct |
36 |
Correct |
169 ms |
18164 KB |
Output is correct |
37 |
Correct |
175 ms |
18116 KB |
Output is correct |
38 |
Correct |
178 ms |
18104 KB |
Output is correct |
39 |
Correct |
176 ms |
18144 KB |
Output is correct |
40 |
Correct |
163 ms |
18248 KB |
Output is correct |
41 |
Correct |
183 ms |
18048 KB |
Output is correct |
42 |
Correct |
174 ms |
18092 KB |
Output is correct |
43 |
Correct |
269 ms |
18376 KB |
Output is correct |
44 |
Correct |
263 ms |
18500 KB |
Output is correct |
45 |
Correct |
265 ms |
18344 KB |
Output is correct |
46 |
Correct |
268 ms |
18364 KB |
Output is correct |
47 |
Correct |
263 ms |
18364 KB |
Output is correct |
48 |
Correct |
279 ms |
18376 KB |
Output is correct |
49 |
Correct |
278 ms |
18376 KB |
Output is correct |
50 |
Correct |
272 ms |
18372 KB |
Output is correct |
51 |
Correct |
262 ms |
18468 KB |
Output is correct |
52 |
Correct |
262 ms |
18244 KB |
Output is correct |
53 |
Correct |
263 ms |
18452 KB |
Output is correct |
54 |
Correct |
267 ms |
18480 KB |
Output is correct |
55 |
Correct |
266 ms |
18472 KB |
Output is correct |
56 |
Correct |
260 ms |
18372 KB |
Output is correct |
57 |
Correct |
268 ms |
18248 KB |
Output is correct |
58 |
Correct |
271 ms |
18476 KB |
Output is correct |
59 |
Correct |
276 ms |
18256 KB |
Output is correct |
60 |
Correct |
270 ms |
18384 KB |
Output is correct |
61 |
Correct |
265 ms |
18300 KB |
Output is correct |
62 |
Correct |
268 ms |
18244 KB |
Output is correct |
63 |
Correct |
274 ms |
18368 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
154 ms |
17512 KB |
Output is correct |
2 |
Correct |
156 ms |
17492 KB |
Output is correct |
3 |
Correct |
156 ms |
17504 KB |
Output is correct |
4 |
Correct |
154 ms |
17444 KB |
Output is correct |
5 |
Correct |
152 ms |
17456 KB |
Output is correct |
6 |
Correct |
159 ms |
17504 KB |
Output is correct |
7 |
Correct |
161 ms |
17428 KB |
Output is correct |
8 |
Correct |
157 ms |
17468 KB |
Output is correct |
9 |
Correct |
155 ms |
17540 KB |
Output is correct |
10 |
Correct |
156 ms |
17476 KB |
Output is correct |
11 |
Correct |
161 ms |
17428 KB |
Output is correct |
12 |
Correct |
155 ms |
17456 KB |
Output is correct |
13 |
Correct |
151 ms |
17476 KB |
Output is correct |
14 |
Correct |
156 ms |
17452 KB |
Output is correct |
15 |
Correct |
159 ms |
17408 KB |
Output is correct |
16 |
Correct |
152 ms |
17476 KB |
Output is correct |
17 |
Correct |
156 ms |
17524 KB |
Output is correct |
18 |
Correct |
159 ms |
17576 KB |
Output is correct |
19 |
Correct |
160 ms |
17392 KB |
Output is correct |
20 |
Correct |
159 ms |
17500 KB |
Output is correct |
21 |
Correct |
161 ms |
17556 KB |
Output is correct |
22 |
Correct |
169 ms |
18144 KB |
Output is correct |
23 |
Correct |
174 ms |
18244 KB |
Output is correct |
24 |
Correct |
164 ms |
18116 KB |
Output is correct |
25 |
Correct |
164 ms |
18116 KB |
Output is correct |
26 |
Correct |
169 ms |
18148 KB |
Output is correct |
27 |
Correct |
169 ms |
18152 KB |
Output is correct |
28 |
Correct |
181 ms |
18124 KB |
Output is correct |
29 |
Correct |
167 ms |
18168 KB |
Output is correct |
30 |
Correct |
166 ms |
18156 KB |
Output is correct |
31 |
Correct |
181 ms |
18116 KB |
Output is correct |
32 |
Correct |
165 ms |
18116 KB |
Output is correct |
33 |
Correct |
162 ms |
18124 KB |
Output is correct |
34 |
Correct |
160 ms |
18204 KB |
Output is correct |
35 |
Correct |
175 ms |
18104 KB |
Output is correct |
36 |
Correct |
169 ms |
18164 KB |
Output is correct |
37 |
Correct |
175 ms |
18116 KB |
Output is correct |
38 |
Correct |
178 ms |
18104 KB |
Output is correct |
39 |
Correct |
176 ms |
18144 KB |
Output is correct |
40 |
Correct |
163 ms |
18248 KB |
Output is correct |
41 |
Correct |
183 ms |
18048 KB |
Output is correct |
42 |
Correct |
174 ms |
18092 KB |
Output is correct |
43 |
Correct |
269 ms |
18376 KB |
Output is correct |
44 |
Correct |
263 ms |
18500 KB |
Output is correct |
45 |
Correct |
265 ms |
18344 KB |
Output is correct |
46 |
Correct |
268 ms |
18364 KB |
Output is correct |
47 |
Correct |
263 ms |
18364 KB |
Output is correct |
48 |
Correct |
279 ms |
18376 KB |
Output is correct |
49 |
Correct |
278 ms |
18376 KB |
Output is correct |
50 |
Correct |
272 ms |
18372 KB |
Output is correct |
51 |
Correct |
262 ms |
18468 KB |
Output is correct |
52 |
Correct |
262 ms |
18244 KB |
Output is correct |
53 |
Correct |
263 ms |
18452 KB |
Output is correct |
54 |
Correct |
267 ms |
18480 KB |
Output is correct |
55 |
Correct |
266 ms |
18472 KB |
Output is correct |
56 |
Correct |
260 ms |
18372 KB |
Output is correct |
57 |
Correct |
268 ms |
18248 KB |
Output is correct |
58 |
Correct |
271 ms |
18476 KB |
Output is correct |
59 |
Correct |
276 ms |
18256 KB |
Output is correct |
60 |
Correct |
270 ms |
18384 KB |
Output is correct |
61 |
Correct |
265 ms |
18300 KB |
Output is correct |
62 |
Correct |
268 ms |
18244 KB |
Output is correct |
63 |
Correct |
274 ms |
18368 KB |
Output is correct |
64 |
Execution timed out |
1185 ms |
18620 KB |
Time limit exceeded |
65 |
Halted |
0 ms |
0 KB |
- |