#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vll = vector<ll>;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using pii = pair<int, int>;
#define sz(x) int(x.size())
const ll mod = 998'244'353LL;
const int Z = 62;
int ad(ll a, ll b)
{
return (a + b) % mod;
}
void selfadd(int& a, ll b)
{
a = ad(a, b);
}
int mul(ll a, ll b)
{
return (a * b) % mod;
}
int getnum(char c)
{
if('a' <= c && c <= 'z')
return c - 'a';
else if('A' <= c && c <= 'Z')
return 26 + c - 'A';
else if('0' <= c && c <= '9')
return 26 + 26 + c - '0';
else
assert(0);
// if('a' <= c && c <= 'z')
// return c - 'a';
// else
// return 16 + c - 'A';
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n;
cin >> n;
set<string> words;
for(int i = 1; i <= n; i++)
{
string s;
cin >> s;
words.insert(s);
reverse(s.begin(), s.end());
words.insert(s);
}
vector<pii> wl[11];
for(string w : words)
{
wl[sz(w)].push_back({getnum(w[0]), getnum(w.back())});
}
// cerr << "done\n";
int res = 0;
for(int l = 3; l <= 10; l++)
{
int cr;
// cerr << "l = " << l << '\n';
vvi ct(Z, vi(Z, 0));
for(pii z : wl[l])
{
ct[z.first][z.second]++;
}
vvvi ct3(Z, vvi(Z, vi(Z, 0)));
for(int a = 0; a < Z; a++)
{
for(int b = a; b < Z; b++)
{
for(int c = b; c < Z; c++)
{
for(int x = 0; x < Z; x++)
{
selfadd(ct3[a][b][c], mul(ct[x][a], mul(ct[x][b], ct[x][c])));
}
}
}
}
//1 unique value
for(int a = 0; a < Z; a++)
selfadd(res, mul(ct3[a][a][a], mul(ct3[a][a][a], mul(ct3[a][a][a], ct3[a][a][a]))));
//2 unique values, 2 + 2
cr = 0;
for(int a = 0; a < Z; a++)
{
for(int b = a+1; b < Z; b++)
{
selfadd(cr, mul(ct3[a][a][b], mul(ct3[a][a][b], mul(ct3[a][b][b], ct3[a][b][b]))));
}
}
selfadd(res, mul(cr, 6));
//2 unique values, 1 + 3
cr = 0;
for(int a = 0; a < Z; a++)
{
for(int b = a+1; b < Z; b++)
{
selfadd(cr, mul(ct3[a][a][a], mul(ct3[a][a][b], mul(ct3[a][a][b], ct3[a][a][b]))));
selfadd(cr, mul(ct3[b][b][b], mul(ct3[a][b][b], mul(ct3[a][b][b], ct3[a][b][b]))));
}
}
selfadd(res, mul(cr, 4));
//3 unique values
cr = 0;
for(int a = 0; a < Z; a++)
{
for(int b = a+1; b < Z; b++)
{
for(int c = b+1; c < Z; c++)
{
//1 + 1 + 2
selfadd(cr, mul(ct3[a][b][c], mul(ct3[a][b][c], mul(ct3[a][c][c], ct3[b][c][c]))));
selfadd(cr, mul(ct3[a][b][c], mul(ct3[a][b][c], mul(ct3[a][a][c], ct3[a][a][b]))));
selfadd(cr, mul(ct3[a][b][c], mul(ct3[a][b][c], mul(ct3[a][b][b], ct3[b][b][c]))));
}
}
}
selfadd(res, mul(12, cr));
//4 unique values
cr = 0;
for(int a = 0; a < Z; a++)
{
for(int b = a+1; b < Z; b++)
{
for(int c = b+1; c < Z; c++)
{
for(int d = c+1; d < Z; d++)
{
selfadd(cr, mul(ct3[a][b][c], mul(ct3[a][b][d], mul(ct3[a][c][d], ct3[b][c][d]))));
}
}
}
}
selfadd(res, mul(cr, 24));
// cerr << l << " : " << res << '\n';
}
cout << res << '\n';
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
257 ms |
17504 KB |
Output is correct |
2 |
Correct |
259 ms |
17580 KB |
Output is correct |
3 |
Correct |
251 ms |
17496 KB |
Output is correct |
4 |
Correct |
287 ms |
17472 KB |
Output is correct |
5 |
Correct |
243 ms |
17496 KB |
Output is correct |
6 |
Correct |
233 ms |
17500 KB |
Output is correct |
7 |
Correct |
243 ms |
17508 KB |
Output is correct |
8 |
Correct |
228 ms |
17492 KB |
Output is correct |
9 |
Correct |
245 ms |
17492 KB |
Output is correct |
10 |
Correct |
234 ms |
17508 KB |
Output is correct |
11 |
Correct |
238 ms |
17496 KB |
Output is correct |
12 |
Correct |
233 ms |
17488 KB |
Output is correct |
13 |
Correct |
230 ms |
17504 KB |
Output is correct |
14 |
Correct |
238 ms |
17492 KB |
Output is correct |
15 |
Correct |
264 ms |
17504 KB |
Output is correct |
16 |
Correct |
254 ms |
17548 KB |
Output is correct |
17 |
Correct |
231 ms |
17492 KB |
Output is correct |
18 |
Correct |
258 ms |
17492 KB |
Output is correct |
19 |
Correct |
258 ms |
17488 KB |
Output is correct |
20 |
Correct |
272 ms |
17500 KB |
Output is correct |
21 |
Correct |
231 ms |
17484 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
257 ms |
17504 KB |
Output is correct |
2 |
Correct |
259 ms |
17580 KB |
Output is correct |
3 |
Correct |
251 ms |
17496 KB |
Output is correct |
4 |
Correct |
287 ms |
17472 KB |
Output is correct |
5 |
Correct |
243 ms |
17496 KB |
Output is correct |
6 |
Correct |
233 ms |
17500 KB |
Output is correct |
7 |
Correct |
243 ms |
17508 KB |
Output is correct |
8 |
Correct |
228 ms |
17492 KB |
Output is correct |
9 |
Correct |
245 ms |
17492 KB |
Output is correct |
10 |
Correct |
234 ms |
17508 KB |
Output is correct |
11 |
Correct |
238 ms |
17496 KB |
Output is correct |
12 |
Correct |
233 ms |
17488 KB |
Output is correct |
13 |
Correct |
230 ms |
17504 KB |
Output is correct |
14 |
Correct |
238 ms |
17492 KB |
Output is correct |
15 |
Correct |
264 ms |
17504 KB |
Output is correct |
16 |
Correct |
254 ms |
17548 KB |
Output is correct |
17 |
Correct |
231 ms |
17492 KB |
Output is correct |
18 |
Correct |
258 ms |
17492 KB |
Output is correct |
19 |
Correct |
258 ms |
17488 KB |
Output is correct |
20 |
Correct |
272 ms |
17500 KB |
Output is correct |
21 |
Correct |
231 ms |
17484 KB |
Output is correct |
22 |
Correct |
245 ms |
18232 KB |
Output is correct |
23 |
Correct |
236 ms |
18216 KB |
Output is correct |
24 |
Correct |
265 ms |
18304 KB |
Output is correct |
25 |
Correct |
228 ms |
18248 KB |
Output is correct |
26 |
Correct |
237 ms |
18200 KB |
Output is correct |
27 |
Correct |
241 ms |
18312 KB |
Output is correct |
28 |
Correct |
229 ms |
18372 KB |
Output is correct |
29 |
Correct |
232 ms |
18276 KB |
Output is correct |
30 |
Correct |
273 ms |
18232 KB |
Output is correct |
31 |
Correct |
227 ms |
18176 KB |
Output is correct |
32 |
Correct |
274 ms |
18236 KB |
Output is correct |
33 |
Correct |
243 ms |
18224 KB |
Output is correct |
34 |
Correct |
233 ms |
18256 KB |
Output is correct |
35 |
Correct |
250 ms |
18212 KB |
Output is correct |
36 |
Correct |
231 ms |
18232 KB |
Output is correct |
37 |
Correct |
244 ms |
18264 KB |
Output is correct |
38 |
Correct |
244 ms |
18196 KB |
Output is correct |
39 |
Correct |
247 ms |
18332 KB |
Output is correct |
40 |
Correct |
257 ms |
18220 KB |
Output is correct |
41 |
Correct |
238 ms |
18184 KB |
Output is correct |
42 |
Correct |
231 ms |
18228 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
257 ms |
17504 KB |
Output is correct |
2 |
Correct |
259 ms |
17580 KB |
Output is correct |
3 |
Correct |
251 ms |
17496 KB |
Output is correct |
4 |
Correct |
287 ms |
17472 KB |
Output is correct |
5 |
Correct |
243 ms |
17496 KB |
Output is correct |
6 |
Correct |
233 ms |
17500 KB |
Output is correct |
7 |
Correct |
243 ms |
17508 KB |
Output is correct |
8 |
Correct |
228 ms |
17492 KB |
Output is correct |
9 |
Correct |
245 ms |
17492 KB |
Output is correct |
10 |
Correct |
234 ms |
17508 KB |
Output is correct |
11 |
Correct |
238 ms |
17496 KB |
Output is correct |
12 |
Correct |
233 ms |
17488 KB |
Output is correct |
13 |
Correct |
230 ms |
17504 KB |
Output is correct |
14 |
Correct |
238 ms |
17492 KB |
Output is correct |
15 |
Correct |
264 ms |
17504 KB |
Output is correct |
16 |
Correct |
254 ms |
17548 KB |
Output is correct |
17 |
Correct |
231 ms |
17492 KB |
Output is correct |
18 |
Correct |
258 ms |
17492 KB |
Output is correct |
19 |
Correct |
258 ms |
17488 KB |
Output is correct |
20 |
Correct |
272 ms |
17500 KB |
Output is correct |
21 |
Correct |
231 ms |
17484 KB |
Output is correct |
22 |
Correct |
245 ms |
18232 KB |
Output is correct |
23 |
Correct |
236 ms |
18216 KB |
Output is correct |
24 |
Correct |
265 ms |
18304 KB |
Output is correct |
25 |
Correct |
228 ms |
18248 KB |
Output is correct |
26 |
Correct |
237 ms |
18200 KB |
Output is correct |
27 |
Correct |
241 ms |
18312 KB |
Output is correct |
28 |
Correct |
229 ms |
18372 KB |
Output is correct |
29 |
Correct |
232 ms |
18276 KB |
Output is correct |
30 |
Correct |
273 ms |
18232 KB |
Output is correct |
31 |
Correct |
227 ms |
18176 KB |
Output is correct |
32 |
Correct |
274 ms |
18236 KB |
Output is correct |
33 |
Correct |
243 ms |
18224 KB |
Output is correct |
34 |
Correct |
233 ms |
18256 KB |
Output is correct |
35 |
Correct |
250 ms |
18212 KB |
Output is correct |
36 |
Correct |
231 ms |
18232 KB |
Output is correct |
37 |
Correct |
244 ms |
18264 KB |
Output is correct |
38 |
Correct |
244 ms |
18196 KB |
Output is correct |
39 |
Correct |
247 ms |
18332 KB |
Output is correct |
40 |
Correct |
257 ms |
18220 KB |
Output is correct |
41 |
Correct |
238 ms |
18184 KB |
Output is correct |
42 |
Correct |
231 ms |
18228 KB |
Output is correct |
43 |
Correct |
231 ms |
18496 KB |
Output is correct |
44 |
Correct |
235 ms |
18664 KB |
Output is correct |
45 |
Correct |
253 ms |
18564 KB |
Output is correct |
46 |
Correct |
241 ms |
18576 KB |
Output is correct |
47 |
Correct |
270 ms |
18580 KB |
Output is correct |
48 |
Correct |
235 ms |
18636 KB |
Output is correct |
49 |
Correct |
275 ms |
18596 KB |
Output is correct |
50 |
Correct |
238 ms |
18776 KB |
Output is correct |
51 |
Correct |
270 ms |
18640 KB |
Output is correct |
52 |
Correct |
243 ms |
18580 KB |
Output is correct |
53 |
Correct |
248 ms |
18632 KB |
Output is correct |
54 |
Correct |
244 ms |
18592 KB |
Output is correct |
55 |
Correct |
237 ms |
18636 KB |
Output is correct |
56 |
Correct |
231 ms |
18640 KB |
Output is correct |
57 |
Correct |
244 ms |
18564 KB |
Output is correct |
58 |
Correct |
273 ms |
18588 KB |
Output is correct |
59 |
Correct |
231 ms |
18624 KB |
Output is correct |
60 |
Correct |
241 ms |
18620 KB |
Output is correct |
61 |
Correct |
248 ms |
18660 KB |
Output is correct |
62 |
Correct |
240 ms |
18592 KB |
Output is correct |
63 |
Correct |
250 ms |
18604 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
257 ms |
17504 KB |
Output is correct |
2 |
Correct |
259 ms |
17580 KB |
Output is correct |
3 |
Correct |
251 ms |
17496 KB |
Output is correct |
4 |
Correct |
287 ms |
17472 KB |
Output is correct |
5 |
Correct |
243 ms |
17496 KB |
Output is correct |
6 |
Correct |
233 ms |
17500 KB |
Output is correct |
7 |
Correct |
243 ms |
17508 KB |
Output is correct |
8 |
Correct |
228 ms |
17492 KB |
Output is correct |
9 |
Correct |
245 ms |
17492 KB |
Output is correct |
10 |
Correct |
234 ms |
17508 KB |
Output is correct |
11 |
Correct |
238 ms |
17496 KB |
Output is correct |
12 |
Correct |
233 ms |
17488 KB |
Output is correct |
13 |
Correct |
230 ms |
17504 KB |
Output is correct |
14 |
Correct |
238 ms |
17492 KB |
Output is correct |
15 |
Correct |
264 ms |
17504 KB |
Output is correct |
16 |
Correct |
254 ms |
17548 KB |
Output is correct |
17 |
Correct |
231 ms |
17492 KB |
Output is correct |
18 |
Correct |
258 ms |
17492 KB |
Output is correct |
19 |
Correct |
258 ms |
17488 KB |
Output is correct |
20 |
Correct |
272 ms |
17500 KB |
Output is correct |
21 |
Correct |
231 ms |
17484 KB |
Output is correct |
22 |
Correct |
245 ms |
18232 KB |
Output is correct |
23 |
Correct |
236 ms |
18216 KB |
Output is correct |
24 |
Correct |
265 ms |
18304 KB |
Output is correct |
25 |
Correct |
228 ms |
18248 KB |
Output is correct |
26 |
Correct |
237 ms |
18200 KB |
Output is correct |
27 |
Correct |
241 ms |
18312 KB |
Output is correct |
28 |
Correct |
229 ms |
18372 KB |
Output is correct |
29 |
Correct |
232 ms |
18276 KB |
Output is correct |
30 |
Correct |
273 ms |
18232 KB |
Output is correct |
31 |
Correct |
227 ms |
18176 KB |
Output is correct |
32 |
Correct |
274 ms |
18236 KB |
Output is correct |
33 |
Correct |
243 ms |
18224 KB |
Output is correct |
34 |
Correct |
233 ms |
18256 KB |
Output is correct |
35 |
Correct |
250 ms |
18212 KB |
Output is correct |
36 |
Correct |
231 ms |
18232 KB |
Output is correct |
37 |
Correct |
244 ms |
18264 KB |
Output is correct |
38 |
Correct |
244 ms |
18196 KB |
Output is correct |
39 |
Correct |
247 ms |
18332 KB |
Output is correct |
40 |
Correct |
257 ms |
18220 KB |
Output is correct |
41 |
Correct |
238 ms |
18184 KB |
Output is correct |
42 |
Correct |
231 ms |
18228 KB |
Output is correct |
43 |
Correct |
231 ms |
18496 KB |
Output is correct |
44 |
Correct |
235 ms |
18664 KB |
Output is correct |
45 |
Correct |
253 ms |
18564 KB |
Output is correct |
46 |
Correct |
241 ms |
18576 KB |
Output is correct |
47 |
Correct |
270 ms |
18580 KB |
Output is correct |
48 |
Correct |
235 ms |
18636 KB |
Output is correct |
49 |
Correct |
275 ms |
18596 KB |
Output is correct |
50 |
Correct |
238 ms |
18776 KB |
Output is correct |
51 |
Correct |
270 ms |
18640 KB |
Output is correct |
52 |
Correct |
243 ms |
18580 KB |
Output is correct |
53 |
Correct |
248 ms |
18632 KB |
Output is correct |
54 |
Correct |
244 ms |
18592 KB |
Output is correct |
55 |
Correct |
237 ms |
18636 KB |
Output is correct |
56 |
Correct |
231 ms |
18640 KB |
Output is correct |
57 |
Correct |
244 ms |
18564 KB |
Output is correct |
58 |
Correct |
273 ms |
18588 KB |
Output is correct |
59 |
Correct |
231 ms |
18624 KB |
Output is correct |
60 |
Correct |
241 ms |
18620 KB |
Output is correct |
61 |
Correct |
248 ms |
18660 KB |
Output is correct |
62 |
Correct |
240 ms |
18592 KB |
Output is correct |
63 |
Correct |
250 ms |
18604 KB |
Output is correct |
64 |
Correct |
265 ms |
18824 KB |
Output is correct |
65 |
Correct |
238 ms |
19316 KB |
Output is correct |
66 |
Correct |
262 ms |
19420 KB |
Output is correct |
67 |
Correct |
257 ms |
19364 KB |
Output is correct |
68 |
Correct |
249 ms |
19320 KB |
Output is correct |
69 |
Correct |
247 ms |
19416 KB |
Output is correct |
70 |
Correct |
249 ms |
19316 KB |
Output is correct |
71 |
Correct |
248 ms |
19364 KB |
Output is correct |
72 |
Correct |
242 ms |
19396 KB |
Output is correct |
73 |
Correct |
239 ms |
19352 KB |
Output is correct |
74 |
Correct |
248 ms |
19364 KB |
Output is correct |
75 |
Correct |
243 ms |
19488 KB |
Output is correct |
76 |
Correct |
241 ms |
19440 KB |
Output is correct |
77 |
Correct |
234 ms |
19316 KB |
Output is correct |
78 |
Correct |
247 ms |
19396 KB |
Output is correct |
79 |
Correct |
258 ms |
19384 KB |
Output is correct |
80 |
Correct |
269 ms |
19388 KB |
Output is correct |
81 |
Correct |
258 ms |
19424 KB |
Output is correct |
82 |
Correct |
252 ms |
19380 KB |
Output is correct |
83 |
Correct |
239 ms |
19432 KB |
Output is correct |
84 |
Correct |
228 ms |
19296 KB |
Output is correct |