//Challenge: Accepted
#include <iostream>
#include <algorithm>
#include <utility>
#include <vector>
#include <stack>
#include <queue>
#include <unordered_set>
#include <assert.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
//using namespace __gnu_pbds;
void debug() {cout << endl;}
template<class T, class ... U> void debug(T a, U ... b) {cout << a << " ", debug(b...);};
template<class T> void pary(T l, T r) {
while (l != r) cout << *l << " ", l++;
cout << endl;
}
#define ll long long
#define maxn 200005
#define maxc 62
#define mod 998244353
#define pii pair<int, int>
#define ff first
#define ss second
#define io ios_base::sync_with_stdio(0);cin.tie(0);
unordered_set<string> se[11];
ll val[maxc][maxc][maxc];
ll cnt[maxc][maxc];
char f(char c) {
if (c >= '0' && c <= '9') return c;
if (c >= 'a' && c <= 'z') return char('0' + 36 + (c - 'a'));
return char ('0' + 10 + (c - 'A'));
}
int main() {
io
int n;
cin >> n;
for (int i = 0;i < n;i++) {
string s;
cin >> s;
for (auto &c:s) c = f(c);
string t = s;
reverse(t.begin(), t.end());
se[s.size()].insert(s);
if (t != s) se[s.size()].insert(t);
}
ll ans = 0;
for (int siz = 3;siz <= 10;siz++) {
for (int i = 0;i < maxc;i++) {
for (int j = 0;j < maxc;j++) {
cnt[i][j] = 0;
}
}
for (auto s:se[siz]) {
cnt[s[0] - '0'][s.back() - '0']++;
}
for (int i = 0;i < maxc;i++) {
for (int j = i;j < maxc;j++) {
for (int k = j;k < maxc;k++) {
val[i][j][k] = 0;
for (int l = 0;l < maxc;l++) {
val[i][j][k] = (val[i][j][k] + cnt[i][l] * cnt[j][l] % mod * cnt[k][l]) % mod;
}
}
}
}
for (int i = 0;i < maxc;i++) {
for (int j = i;j < maxc;j++) {
for (int k = j;k < maxc;k++) {
for (int l = k;l < maxc;l++) {
ll x = (val[i][j][k] * val[i][j][l] % mod * val[i][k][l] % mod * val[j][k][l]) % mod;
int mult = 24;
if (i == j) {
if (j == k) mult = k == l ? 1 : 4;
else mult = k == l ? 6 : 12;
} else {
if (j == k) mult = k == l ? 4 : 12;
else mult = k == l ? 12 : 24;
}
ans = (ans + x * mult) % mod;
}
}
}
}
}
cout << ans << endl;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
258 ms |
14864 KB |
Output is correct |
2 |
Correct |
261 ms |
14864 KB |
Output is correct |
3 |
Correct |
291 ms |
14868 KB |
Output is correct |
4 |
Correct |
262 ms |
14796 KB |
Output is correct |
5 |
Correct |
257 ms |
14868 KB |
Output is correct |
6 |
Correct |
253 ms |
14904 KB |
Output is correct |
7 |
Correct |
286 ms |
14932 KB |
Output is correct |
8 |
Correct |
261 ms |
14880 KB |
Output is correct |
9 |
Correct |
260 ms |
14940 KB |
Output is correct |
10 |
Correct |
282 ms |
14864 KB |
Output is correct |
11 |
Correct |
261 ms |
14864 KB |
Output is correct |
12 |
Correct |
257 ms |
14856 KB |
Output is correct |
13 |
Correct |
264 ms |
14880 KB |
Output is correct |
14 |
Correct |
278 ms |
14976 KB |
Output is correct |
15 |
Correct |
263 ms |
14892 KB |
Output is correct |
16 |
Correct |
265 ms |
14864 KB |
Output is correct |
17 |
Correct |
263 ms |
14860 KB |
Output is correct |
18 |
Correct |
261 ms |
14792 KB |
Output is correct |
19 |
Correct |
266 ms |
14868 KB |
Output is correct |
20 |
Correct |
259 ms |
15052 KB |
Output is correct |
21 |
Correct |
259 ms |
14740 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
258 ms |
14864 KB |
Output is correct |
2 |
Correct |
261 ms |
14864 KB |
Output is correct |
3 |
Correct |
291 ms |
14868 KB |
Output is correct |
4 |
Correct |
262 ms |
14796 KB |
Output is correct |
5 |
Correct |
257 ms |
14868 KB |
Output is correct |
6 |
Correct |
253 ms |
14904 KB |
Output is correct |
7 |
Correct |
286 ms |
14932 KB |
Output is correct |
8 |
Correct |
261 ms |
14880 KB |
Output is correct |
9 |
Correct |
260 ms |
14940 KB |
Output is correct |
10 |
Correct |
282 ms |
14864 KB |
Output is correct |
11 |
Correct |
261 ms |
14864 KB |
Output is correct |
12 |
Correct |
257 ms |
14856 KB |
Output is correct |
13 |
Correct |
264 ms |
14880 KB |
Output is correct |
14 |
Correct |
278 ms |
14976 KB |
Output is correct |
15 |
Correct |
263 ms |
14892 KB |
Output is correct |
16 |
Correct |
265 ms |
14864 KB |
Output is correct |
17 |
Correct |
263 ms |
14860 KB |
Output is correct |
18 |
Correct |
261 ms |
14792 KB |
Output is correct |
19 |
Correct |
266 ms |
14868 KB |
Output is correct |
20 |
Correct |
259 ms |
15052 KB |
Output is correct |
21 |
Correct |
259 ms |
14740 KB |
Output is correct |
22 |
Correct |
257 ms |
15944 KB |
Output is correct |
23 |
Correct |
259 ms |
16036 KB |
Output is correct |
24 |
Correct |
293 ms |
16024 KB |
Output is correct |
25 |
Correct |
247 ms |
15952 KB |
Output is correct |
26 |
Correct |
255 ms |
16072 KB |
Output is correct |
27 |
Correct |
262 ms |
16112 KB |
Output is correct |
28 |
Correct |
254 ms |
16064 KB |
Output is correct |
29 |
Correct |
281 ms |
16008 KB |
Output is correct |
30 |
Correct |
267 ms |
16088 KB |
Output is correct |
31 |
Correct |
255 ms |
15920 KB |
Output is correct |
32 |
Correct |
254 ms |
16044 KB |
Output is correct |
33 |
Correct |
269 ms |
15976 KB |
Output is correct |
34 |
Correct |
257 ms |
16012 KB |
Output is correct |
35 |
Correct |
254 ms |
16044 KB |
Output is correct |
36 |
Correct |
256 ms |
16000 KB |
Output is correct |
37 |
Correct |
256 ms |
16016 KB |
Output is correct |
38 |
Correct |
267 ms |
15992 KB |
Output is correct |
39 |
Correct |
252 ms |
15976 KB |
Output is correct |
40 |
Correct |
258 ms |
16004 KB |
Output is correct |
41 |
Correct |
256 ms |
16020 KB |
Output is correct |
42 |
Correct |
259 ms |
16072 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
258 ms |
14864 KB |
Output is correct |
2 |
Correct |
261 ms |
14864 KB |
Output is correct |
3 |
Correct |
291 ms |
14868 KB |
Output is correct |
4 |
Correct |
262 ms |
14796 KB |
Output is correct |
5 |
Correct |
257 ms |
14868 KB |
Output is correct |
6 |
Correct |
253 ms |
14904 KB |
Output is correct |
7 |
Correct |
286 ms |
14932 KB |
Output is correct |
8 |
Correct |
261 ms |
14880 KB |
Output is correct |
9 |
Correct |
260 ms |
14940 KB |
Output is correct |
10 |
Correct |
282 ms |
14864 KB |
Output is correct |
11 |
Correct |
261 ms |
14864 KB |
Output is correct |
12 |
Correct |
257 ms |
14856 KB |
Output is correct |
13 |
Correct |
264 ms |
14880 KB |
Output is correct |
14 |
Correct |
278 ms |
14976 KB |
Output is correct |
15 |
Correct |
263 ms |
14892 KB |
Output is correct |
16 |
Correct |
265 ms |
14864 KB |
Output is correct |
17 |
Correct |
263 ms |
14860 KB |
Output is correct |
18 |
Correct |
261 ms |
14792 KB |
Output is correct |
19 |
Correct |
266 ms |
14868 KB |
Output is correct |
20 |
Correct |
259 ms |
15052 KB |
Output is correct |
21 |
Correct |
259 ms |
14740 KB |
Output is correct |
22 |
Correct |
257 ms |
15944 KB |
Output is correct |
23 |
Correct |
259 ms |
16036 KB |
Output is correct |
24 |
Correct |
293 ms |
16024 KB |
Output is correct |
25 |
Correct |
247 ms |
15952 KB |
Output is correct |
26 |
Correct |
255 ms |
16072 KB |
Output is correct |
27 |
Correct |
262 ms |
16112 KB |
Output is correct |
28 |
Correct |
254 ms |
16064 KB |
Output is correct |
29 |
Correct |
281 ms |
16008 KB |
Output is correct |
30 |
Correct |
267 ms |
16088 KB |
Output is correct |
31 |
Correct |
255 ms |
15920 KB |
Output is correct |
32 |
Correct |
254 ms |
16044 KB |
Output is correct |
33 |
Correct |
269 ms |
15976 KB |
Output is correct |
34 |
Correct |
257 ms |
16012 KB |
Output is correct |
35 |
Correct |
254 ms |
16044 KB |
Output is correct |
36 |
Correct |
256 ms |
16000 KB |
Output is correct |
37 |
Correct |
256 ms |
16016 KB |
Output is correct |
38 |
Correct |
267 ms |
15992 KB |
Output is correct |
39 |
Correct |
252 ms |
15976 KB |
Output is correct |
40 |
Correct |
258 ms |
16004 KB |
Output is correct |
41 |
Correct |
256 ms |
16020 KB |
Output is correct |
42 |
Correct |
259 ms |
16072 KB |
Output is correct |
43 |
Correct |
252 ms |
16300 KB |
Output is correct |
44 |
Correct |
275 ms |
16188 KB |
Output is correct |
45 |
Correct |
255 ms |
16416 KB |
Output is correct |
46 |
Correct |
264 ms |
16332 KB |
Output is correct |
47 |
Correct |
267 ms |
16288 KB |
Output is correct |
48 |
Correct |
255 ms |
16320 KB |
Output is correct |
49 |
Correct |
253 ms |
16192 KB |
Output is correct |
50 |
Correct |
259 ms |
16196 KB |
Output is correct |
51 |
Correct |
268 ms |
16200 KB |
Output is correct |
52 |
Correct |
282 ms |
16276 KB |
Output is correct |
53 |
Correct |
259 ms |
16368 KB |
Output is correct |
54 |
Correct |
258 ms |
16368 KB |
Output is correct |
55 |
Correct |
255 ms |
16236 KB |
Output is correct |
56 |
Correct |
258 ms |
16416 KB |
Output is correct |
57 |
Correct |
258 ms |
16216 KB |
Output is correct |
58 |
Correct |
270 ms |
16292 KB |
Output is correct |
59 |
Correct |
270 ms |
16360 KB |
Output is correct |
60 |
Correct |
256 ms |
16248 KB |
Output is correct |
61 |
Correct |
275 ms |
16296 KB |
Output is correct |
62 |
Correct |
266 ms |
16248 KB |
Output is correct |
63 |
Correct |
261 ms |
16292 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
258 ms |
14864 KB |
Output is correct |
2 |
Correct |
261 ms |
14864 KB |
Output is correct |
3 |
Correct |
291 ms |
14868 KB |
Output is correct |
4 |
Correct |
262 ms |
14796 KB |
Output is correct |
5 |
Correct |
257 ms |
14868 KB |
Output is correct |
6 |
Correct |
253 ms |
14904 KB |
Output is correct |
7 |
Correct |
286 ms |
14932 KB |
Output is correct |
8 |
Correct |
261 ms |
14880 KB |
Output is correct |
9 |
Correct |
260 ms |
14940 KB |
Output is correct |
10 |
Correct |
282 ms |
14864 KB |
Output is correct |
11 |
Correct |
261 ms |
14864 KB |
Output is correct |
12 |
Correct |
257 ms |
14856 KB |
Output is correct |
13 |
Correct |
264 ms |
14880 KB |
Output is correct |
14 |
Correct |
278 ms |
14976 KB |
Output is correct |
15 |
Correct |
263 ms |
14892 KB |
Output is correct |
16 |
Correct |
265 ms |
14864 KB |
Output is correct |
17 |
Correct |
263 ms |
14860 KB |
Output is correct |
18 |
Correct |
261 ms |
14792 KB |
Output is correct |
19 |
Correct |
266 ms |
14868 KB |
Output is correct |
20 |
Correct |
259 ms |
15052 KB |
Output is correct |
21 |
Correct |
259 ms |
14740 KB |
Output is correct |
22 |
Correct |
257 ms |
15944 KB |
Output is correct |
23 |
Correct |
259 ms |
16036 KB |
Output is correct |
24 |
Correct |
293 ms |
16024 KB |
Output is correct |
25 |
Correct |
247 ms |
15952 KB |
Output is correct |
26 |
Correct |
255 ms |
16072 KB |
Output is correct |
27 |
Correct |
262 ms |
16112 KB |
Output is correct |
28 |
Correct |
254 ms |
16064 KB |
Output is correct |
29 |
Correct |
281 ms |
16008 KB |
Output is correct |
30 |
Correct |
267 ms |
16088 KB |
Output is correct |
31 |
Correct |
255 ms |
15920 KB |
Output is correct |
32 |
Correct |
254 ms |
16044 KB |
Output is correct |
33 |
Correct |
269 ms |
15976 KB |
Output is correct |
34 |
Correct |
257 ms |
16012 KB |
Output is correct |
35 |
Correct |
254 ms |
16044 KB |
Output is correct |
36 |
Correct |
256 ms |
16000 KB |
Output is correct |
37 |
Correct |
256 ms |
16016 KB |
Output is correct |
38 |
Correct |
267 ms |
15992 KB |
Output is correct |
39 |
Correct |
252 ms |
15976 KB |
Output is correct |
40 |
Correct |
258 ms |
16004 KB |
Output is correct |
41 |
Correct |
256 ms |
16020 KB |
Output is correct |
42 |
Correct |
259 ms |
16072 KB |
Output is correct |
43 |
Correct |
252 ms |
16300 KB |
Output is correct |
44 |
Correct |
275 ms |
16188 KB |
Output is correct |
45 |
Correct |
255 ms |
16416 KB |
Output is correct |
46 |
Correct |
264 ms |
16332 KB |
Output is correct |
47 |
Correct |
267 ms |
16288 KB |
Output is correct |
48 |
Correct |
255 ms |
16320 KB |
Output is correct |
49 |
Correct |
253 ms |
16192 KB |
Output is correct |
50 |
Correct |
259 ms |
16196 KB |
Output is correct |
51 |
Correct |
268 ms |
16200 KB |
Output is correct |
52 |
Correct |
282 ms |
16276 KB |
Output is correct |
53 |
Correct |
259 ms |
16368 KB |
Output is correct |
54 |
Correct |
258 ms |
16368 KB |
Output is correct |
55 |
Correct |
255 ms |
16236 KB |
Output is correct |
56 |
Correct |
258 ms |
16416 KB |
Output is correct |
57 |
Correct |
258 ms |
16216 KB |
Output is correct |
58 |
Correct |
270 ms |
16292 KB |
Output is correct |
59 |
Correct |
270 ms |
16360 KB |
Output is correct |
60 |
Correct |
256 ms |
16248 KB |
Output is correct |
61 |
Correct |
275 ms |
16296 KB |
Output is correct |
62 |
Correct |
266 ms |
16248 KB |
Output is correct |
63 |
Correct |
261 ms |
16292 KB |
Output is correct |
64 |
Correct |
260 ms |
16712 KB |
Output is correct |
65 |
Correct |
276 ms |
16768 KB |
Output is correct |
66 |
Correct |
266 ms |
16648 KB |
Output is correct |
67 |
Correct |
271 ms |
16724 KB |
Output is correct |
68 |
Correct |
267 ms |
16644 KB |
Output is correct |
69 |
Correct |
260 ms |
16656 KB |
Output is correct |
70 |
Correct |
263 ms |
16536 KB |
Output is correct |
71 |
Correct |
269 ms |
16652 KB |
Output is correct |
72 |
Correct |
273 ms |
16740 KB |
Output is correct |
73 |
Correct |
261 ms |
16628 KB |
Output is correct |
74 |
Correct |
262 ms |
16652 KB |
Output is correct |
75 |
Correct |
262 ms |
16676 KB |
Output is correct |
76 |
Correct |
262 ms |
16636 KB |
Output is correct |
77 |
Correct |
268 ms |
16652 KB |
Output is correct |
78 |
Correct |
275 ms |
16652 KB |
Output is correct |
79 |
Correct |
284 ms |
16648 KB |
Output is correct |
80 |
Correct |
263 ms |
16664 KB |
Output is correct |
81 |
Correct |
280 ms |
16656 KB |
Output is correct |
82 |
Correct |
272 ms |
16584 KB |
Output is correct |
83 |
Correct |
269 ms |
16656 KB |
Output is correct |
84 |
Correct |
261 ms |
16592 KB |
Output is correct |