#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 = 32;
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);
}
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++)
{
// 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 = 0; b < Z; b++)
{
for(int c = 0; 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])));
}
}
}
}
for(int a = 0; a < Z; a++)
{
for(int b = 0; b < Z; b++)
{
for(int c = 0; c < Z; c++)
{
for(int d = 0; d < Z; d++)
{
selfadd(res, mul(ct3[a][b][c], mul(ct3[b][c][d], mul(ct3[c][d][a], ct3[d][a][b]))));
}
}
}
}
}
cout << res << '\n';
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
221 ms |
16496 KB |
Output is correct |
2 |
Correct |
214 ms |
16396 KB |
Output is correct |
3 |
Correct |
206 ms |
16536 KB |
Output is correct |
4 |
Correct |
218 ms |
16624 KB |
Output is correct |
5 |
Correct |
205 ms |
16820 KB |
Output is correct |
6 |
Correct |
203 ms |
16764 KB |
Output is correct |
7 |
Correct |
220 ms |
16484 KB |
Output is correct |
8 |
Correct |
200 ms |
16688 KB |
Output is correct |
9 |
Correct |
191 ms |
16452 KB |
Output is correct |
10 |
Correct |
196 ms |
16608 KB |
Output is correct |
11 |
Correct |
209 ms |
16452 KB |
Output is correct |
12 |
Correct |
200 ms |
16520 KB |
Output is correct |
13 |
Correct |
193 ms |
16556 KB |
Output is correct |
14 |
Correct |
193 ms |
16476 KB |
Output is correct |
15 |
Correct |
225 ms |
16484 KB |
Output is correct |
16 |
Correct |
192 ms |
16748 KB |
Output is correct |
17 |
Correct |
200 ms |
16676 KB |
Output is correct |
18 |
Correct |
201 ms |
16772 KB |
Output is correct |
19 |
Correct |
193 ms |
16684 KB |
Output is correct |
20 |
Correct |
215 ms |
16676 KB |
Output is correct |
21 |
Correct |
209 ms |
16448 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
221 ms |
16496 KB |
Output is correct |
2 |
Correct |
214 ms |
16396 KB |
Output is correct |
3 |
Correct |
206 ms |
16536 KB |
Output is correct |
4 |
Correct |
218 ms |
16624 KB |
Output is correct |
5 |
Correct |
205 ms |
16820 KB |
Output is correct |
6 |
Correct |
203 ms |
16764 KB |
Output is correct |
7 |
Correct |
220 ms |
16484 KB |
Output is correct |
8 |
Correct |
200 ms |
16688 KB |
Output is correct |
9 |
Correct |
191 ms |
16452 KB |
Output is correct |
10 |
Correct |
196 ms |
16608 KB |
Output is correct |
11 |
Correct |
209 ms |
16452 KB |
Output is correct |
12 |
Correct |
200 ms |
16520 KB |
Output is correct |
13 |
Correct |
193 ms |
16556 KB |
Output is correct |
14 |
Correct |
193 ms |
16476 KB |
Output is correct |
15 |
Correct |
225 ms |
16484 KB |
Output is correct |
16 |
Correct |
192 ms |
16748 KB |
Output is correct |
17 |
Correct |
200 ms |
16676 KB |
Output is correct |
18 |
Correct |
201 ms |
16772 KB |
Output is correct |
19 |
Correct |
193 ms |
16684 KB |
Output is correct |
20 |
Correct |
215 ms |
16676 KB |
Output is correct |
21 |
Correct |
209 ms |
16448 KB |
Output is correct |
22 |
Correct |
203 ms |
17196 KB |
Output is correct |
23 |
Correct |
211 ms |
17252 KB |
Output is correct |
24 |
Correct |
209 ms |
17280 KB |
Output is correct |
25 |
Correct |
198 ms |
17208 KB |
Output is correct |
26 |
Correct |
192 ms |
17164 KB |
Output is correct |
27 |
Correct |
212 ms |
17336 KB |
Output is correct |
28 |
Correct |
199 ms |
17392 KB |
Output is correct |
29 |
Correct |
192 ms |
17204 KB |
Output is correct |
30 |
Correct |
205 ms |
17200 KB |
Output is correct |
31 |
Correct |
213 ms |
17216 KB |
Output is correct |
32 |
Correct |
211 ms |
17404 KB |
Output is correct |
33 |
Correct |
199 ms |
17192 KB |
Output is correct |
34 |
Correct |
204 ms |
17392 KB |
Output is correct |
35 |
Correct |
197 ms |
17176 KB |
Output is correct |
36 |
Correct |
194 ms |
17492 KB |
Output is correct |
37 |
Correct |
191 ms |
17140 KB |
Output is correct |
38 |
Correct |
196 ms |
17256 KB |
Output is correct |
39 |
Correct |
196 ms |
17344 KB |
Output is correct |
40 |
Correct |
200 ms |
17180 KB |
Output is correct |
41 |
Correct |
210 ms |
17208 KB |
Output is correct |
42 |
Correct |
195 ms |
17124 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
221 ms |
16496 KB |
Output is correct |
2 |
Correct |
214 ms |
16396 KB |
Output is correct |
3 |
Correct |
206 ms |
16536 KB |
Output is correct |
4 |
Correct |
218 ms |
16624 KB |
Output is correct |
5 |
Correct |
205 ms |
16820 KB |
Output is correct |
6 |
Correct |
203 ms |
16764 KB |
Output is correct |
7 |
Correct |
220 ms |
16484 KB |
Output is correct |
8 |
Correct |
200 ms |
16688 KB |
Output is correct |
9 |
Correct |
191 ms |
16452 KB |
Output is correct |
10 |
Correct |
196 ms |
16608 KB |
Output is correct |
11 |
Correct |
209 ms |
16452 KB |
Output is correct |
12 |
Correct |
200 ms |
16520 KB |
Output is correct |
13 |
Correct |
193 ms |
16556 KB |
Output is correct |
14 |
Correct |
193 ms |
16476 KB |
Output is correct |
15 |
Correct |
225 ms |
16484 KB |
Output is correct |
16 |
Correct |
192 ms |
16748 KB |
Output is correct |
17 |
Correct |
200 ms |
16676 KB |
Output is correct |
18 |
Correct |
201 ms |
16772 KB |
Output is correct |
19 |
Correct |
193 ms |
16684 KB |
Output is correct |
20 |
Correct |
215 ms |
16676 KB |
Output is correct |
21 |
Correct |
209 ms |
16448 KB |
Output is correct |
22 |
Correct |
203 ms |
17196 KB |
Output is correct |
23 |
Correct |
211 ms |
17252 KB |
Output is correct |
24 |
Correct |
209 ms |
17280 KB |
Output is correct |
25 |
Correct |
198 ms |
17208 KB |
Output is correct |
26 |
Correct |
192 ms |
17164 KB |
Output is correct |
27 |
Correct |
212 ms |
17336 KB |
Output is correct |
28 |
Correct |
199 ms |
17392 KB |
Output is correct |
29 |
Correct |
192 ms |
17204 KB |
Output is correct |
30 |
Correct |
205 ms |
17200 KB |
Output is correct |
31 |
Correct |
213 ms |
17216 KB |
Output is correct |
32 |
Correct |
211 ms |
17404 KB |
Output is correct |
33 |
Correct |
199 ms |
17192 KB |
Output is correct |
34 |
Correct |
204 ms |
17392 KB |
Output is correct |
35 |
Correct |
197 ms |
17176 KB |
Output is correct |
36 |
Correct |
194 ms |
17492 KB |
Output is correct |
37 |
Correct |
191 ms |
17140 KB |
Output is correct |
38 |
Correct |
196 ms |
17256 KB |
Output is correct |
39 |
Correct |
196 ms |
17344 KB |
Output is correct |
40 |
Correct |
200 ms |
17180 KB |
Output is correct |
41 |
Correct |
210 ms |
17208 KB |
Output is correct |
42 |
Correct |
195 ms |
17124 KB |
Output is correct |
43 |
Runtime error |
108 ms |
35676 KB |
Execution killed with signal 11 |
44 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
221 ms |
16496 KB |
Output is correct |
2 |
Correct |
214 ms |
16396 KB |
Output is correct |
3 |
Correct |
206 ms |
16536 KB |
Output is correct |
4 |
Correct |
218 ms |
16624 KB |
Output is correct |
5 |
Correct |
205 ms |
16820 KB |
Output is correct |
6 |
Correct |
203 ms |
16764 KB |
Output is correct |
7 |
Correct |
220 ms |
16484 KB |
Output is correct |
8 |
Correct |
200 ms |
16688 KB |
Output is correct |
9 |
Correct |
191 ms |
16452 KB |
Output is correct |
10 |
Correct |
196 ms |
16608 KB |
Output is correct |
11 |
Correct |
209 ms |
16452 KB |
Output is correct |
12 |
Correct |
200 ms |
16520 KB |
Output is correct |
13 |
Correct |
193 ms |
16556 KB |
Output is correct |
14 |
Correct |
193 ms |
16476 KB |
Output is correct |
15 |
Correct |
225 ms |
16484 KB |
Output is correct |
16 |
Correct |
192 ms |
16748 KB |
Output is correct |
17 |
Correct |
200 ms |
16676 KB |
Output is correct |
18 |
Correct |
201 ms |
16772 KB |
Output is correct |
19 |
Correct |
193 ms |
16684 KB |
Output is correct |
20 |
Correct |
215 ms |
16676 KB |
Output is correct |
21 |
Correct |
209 ms |
16448 KB |
Output is correct |
22 |
Correct |
203 ms |
17196 KB |
Output is correct |
23 |
Correct |
211 ms |
17252 KB |
Output is correct |
24 |
Correct |
209 ms |
17280 KB |
Output is correct |
25 |
Correct |
198 ms |
17208 KB |
Output is correct |
26 |
Correct |
192 ms |
17164 KB |
Output is correct |
27 |
Correct |
212 ms |
17336 KB |
Output is correct |
28 |
Correct |
199 ms |
17392 KB |
Output is correct |
29 |
Correct |
192 ms |
17204 KB |
Output is correct |
30 |
Correct |
205 ms |
17200 KB |
Output is correct |
31 |
Correct |
213 ms |
17216 KB |
Output is correct |
32 |
Correct |
211 ms |
17404 KB |
Output is correct |
33 |
Correct |
199 ms |
17192 KB |
Output is correct |
34 |
Correct |
204 ms |
17392 KB |
Output is correct |
35 |
Correct |
197 ms |
17176 KB |
Output is correct |
36 |
Correct |
194 ms |
17492 KB |
Output is correct |
37 |
Correct |
191 ms |
17140 KB |
Output is correct |
38 |
Correct |
196 ms |
17256 KB |
Output is correct |
39 |
Correct |
196 ms |
17344 KB |
Output is correct |
40 |
Correct |
200 ms |
17180 KB |
Output is correct |
41 |
Correct |
210 ms |
17208 KB |
Output is correct |
42 |
Correct |
195 ms |
17124 KB |
Output is correct |
43 |
Runtime error |
108 ms |
35676 KB |
Execution killed with signal 11 |
44 |
Halted |
0 ms |
0 KB |
- |