#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 = 16;
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 |
114 ms |
16476 KB |
Output is correct |
2 |
Correct |
99 ms |
16508 KB |
Output is correct |
3 |
Correct |
100 ms |
16448 KB |
Output is correct |
4 |
Correct |
121 ms |
16616 KB |
Output is correct |
5 |
Correct |
102 ms |
16712 KB |
Output is correct |
6 |
Correct |
117 ms |
16720 KB |
Output is correct |
7 |
Correct |
101 ms |
16468 KB |
Output is correct |
8 |
Correct |
98 ms |
16736 KB |
Output is correct |
9 |
Correct |
103 ms |
16452 KB |
Output is correct |
10 |
Correct |
111 ms |
16576 KB |
Output is correct |
11 |
Correct |
105 ms |
16464 KB |
Output is correct |
12 |
Correct |
99 ms |
16508 KB |
Output is correct |
13 |
Correct |
108 ms |
16532 KB |
Output is correct |
14 |
Correct |
107 ms |
16404 KB |
Output is correct |
15 |
Correct |
98 ms |
16400 KB |
Output is correct |
16 |
Correct |
100 ms |
16756 KB |
Output is correct |
17 |
Correct |
101 ms |
16784 KB |
Output is correct |
18 |
Correct |
100 ms |
16692 KB |
Output is correct |
19 |
Correct |
105 ms |
16760 KB |
Output is correct |
20 |
Correct |
120 ms |
16728 KB |
Output is correct |
21 |
Correct |
100 ms |
16516 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
114 ms |
16476 KB |
Output is correct |
2 |
Correct |
99 ms |
16508 KB |
Output is correct |
3 |
Correct |
100 ms |
16448 KB |
Output is correct |
4 |
Correct |
121 ms |
16616 KB |
Output is correct |
5 |
Correct |
102 ms |
16712 KB |
Output is correct |
6 |
Correct |
117 ms |
16720 KB |
Output is correct |
7 |
Correct |
101 ms |
16468 KB |
Output is correct |
8 |
Correct |
98 ms |
16736 KB |
Output is correct |
9 |
Correct |
103 ms |
16452 KB |
Output is correct |
10 |
Correct |
111 ms |
16576 KB |
Output is correct |
11 |
Correct |
105 ms |
16464 KB |
Output is correct |
12 |
Correct |
99 ms |
16508 KB |
Output is correct |
13 |
Correct |
108 ms |
16532 KB |
Output is correct |
14 |
Correct |
107 ms |
16404 KB |
Output is correct |
15 |
Correct |
98 ms |
16400 KB |
Output is correct |
16 |
Correct |
100 ms |
16756 KB |
Output is correct |
17 |
Correct |
101 ms |
16784 KB |
Output is correct |
18 |
Correct |
100 ms |
16692 KB |
Output is correct |
19 |
Correct |
105 ms |
16760 KB |
Output is correct |
20 |
Correct |
120 ms |
16728 KB |
Output is correct |
21 |
Correct |
100 ms |
16516 KB |
Output is correct |
22 |
Correct |
98 ms |
17120 KB |
Output is correct |
23 |
Correct |
101 ms |
18020 KB |
Output is correct |
24 |
Correct |
112 ms |
18056 KB |
Output is correct |
25 |
Correct |
139 ms |
17904 KB |
Output is correct |
26 |
Correct |
103 ms |
17884 KB |
Output is correct |
27 |
Correct |
106 ms |
18204 KB |
Output is correct |
28 |
Correct |
102 ms |
18176 KB |
Output is correct |
29 |
Correct |
115 ms |
18200 KB |
Output is correct |
30 |
Correct |
100 ms |
17824 KB |
Output is correct |
31 |
Correct |
107 ms |
17936 KB |
Output is correct |
32 |
Correct |
102 ms |
18176 KB |
Output is correct |
33 |
Correct |
100 ms |
17948 KB |
Output is correct |
34 |
Correct |
111 ms |
18092 KB |
Output is correct |
35 |
Correct |
108 ms |
17904 KB |
Output is correct |
36 |
Correct |
108 ms |
18176 KB |
Output is correct |
37 |
Correct |
108 ms |
17872 KB |
Output is correct |
38 |
Correct |
102 ms |
17948 KB |
Output is correct |
39 |
Correct |
109 ms |
18076 KB |
Output is correct |
40 |
Correct |
105 ms |
17784 KB |
Output is correct |
41 |
Correct |
100 ms |
18032 KB |
Output is correct |
42 |
Correct |
109 ms |
17832 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
114 ms |
16476 KB |
Output is correct |
2 |
Correct |
99 ms |
16508 KB |
Output is correct |
3 |
Correct |
100 ms |
16448 KB |
Output is correct |
4 |
Correct |
121 ms |
16616 KB |
Output is correct |
5 |
Correct |
102 ms |
16712 KB |
Output is correct |
6 |
Correct |
117 ms |
16720 KB |
Output is correct |
7 |
Correct |
101 ms |
16468 KB |
Output is correct |
8 |
Correct |
98 ms |
16736 KB |
Output is correct |
9 |
Correct |
103 ms |
16452 KB |
Output is correct |
10 |
Correct |
111 ms |
16576 KB |
Output is correct |
11 |
Correct |
105 ms |
16464 KB |
Output is correct |
12 |
Correct |
99 ms |
16508 KB |
Output is correct |
13 |
Correct |
108 ms |
16532 KB |
Output is correct |
14 |
Correct |
107 ms |
16404 KB |
Output is correct |
15 |
Correct |
98 ms |
16400 KB |
Output is correct |
16 |
Correct |
100 ms |
16756 KB |
Output is correct |
17 |
Correct |
101 ms |
16784 KB |
Output is correct |
18 |
Correct |
100 ms |
16692 KB |
Output is correct |
19 |
Correct |
105 ms |
16760 KB |
Output is correct |
20 |
Correct |
120 ms |
16728 KB |
Output is correct |
21 |
Correct |
100 ms |
16516 KB |
Output is correct |
22 |
Correct |
98 ms |
17120 KB |
Output is correct |
23 |
Correct |
101 ms |
18020 KB |
Output is correct |
24 |
Correct |
112 ms |
18056 KB |
Output is correct |
25 |
Correct |
139 ms |
17904 KB |
Output is correct |
26 |
Correct |
103 ms |
17884 KB |
Output is correct |
27 |
Correct |
106 ms |
18204 KB |
Output is correct |
28 |
Correct |
102 ms |
18176 KB |
Output is correct |
29 |
Correct |
115 ms |
18200 KB |
Output is correct |
30 |
Correct |
100 ms |
17824 KB |
Output is correct |
31 |
Correct |
107 ms |
17936 KB |
Output is correct |
32 |
Correct |
102 ms |
18176 KB |
Output is correct |
33 |
Correct |
100 ms |
17948 KB |
Output is correct |
34 |
Correct |
111 ms |
18092 KB |
Output is correct |
35 |
Correct |
108 ms |
17904 KB |
Output is correct |
36 |
Correct |
108 ms |
18176 KB |
Output is correct |
37 |
Correct |
108 ms |
17872 KB |
Output is correct |
38 |
Correct |
102 ms |
17948 KB |
Output is correct |
39 |
Correct |
109 ms |
18076 KB |
Output is correct |
40 |
Correct |
105 ms |
17784 KB |
Output is correct |
41 |
Correct |
100 ms |
18032 KB |
Output is correct |
42 |
Correct |
109 ms |
17832 KB |
Output is correct |
43 |
Runtime error |
122 ms |
36360 KB |
Execution killed with signal 11 |
44 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
114 ms |
16476 KB |
Output is correct |
2 |
Correct |
99 ms |
16508 KB |
Output is correct |
3 |
Correct |
100 ms |
16448 KB |
Output is correct |
4 |
Correct |
121 ms |
16616 KB |
Output is correct |
5 |
Correct |
102 ms |
16712 KB |
Output is correct |
6 |
Correct |
117 ms |
16720 KB |
Output is correct |
7 |
Correct |
101 ms |
16468 KB |
Output is correct |
8 |
Correct |
98 ms |
16736 KB |
Output is correct |
9 |
Correct |
103 ms |
16452 KB |
Output is correct |
10 |
Correct |
111 ms |
16576 KB |
Output is correct |
11 |
Correct |
105 ms |
16464 KB |
Output is correct |
12 |
Correct |
99 ms |
16508 KB |
Output is correct |
13 |
Correct |
108 ms |
16532 KB |
Output is correct |
14 |
Correct |
107 ms |
16404 KB |
Output is correct |
15 |
Correct |
98 ms |
16400 KB |
Output is correct |
16 |
Correct |
100 ms |
16756 KB |
Output is correct |
17 |
Correct |
101 ms |
16784 KB |
Output is correct |
18 |
Correct |
100 ms |
16692 KB |
Output is correct |
19 |
Correct |
105 ms |
16760 KB |
Output is correct |
20 |
Correct |
120 ms |
16728 KB |
Output is correct |
21 |
Correct |
100 ms |
16516 KB |
Output is correct |
22 |
Correct |
98 ms |
17120 KB |
Output is correct |
23 |
Correct |
101 ms |
18020 KB |
Output is correct |
24 |
Correct |
112 ms |
18056 KB |
Output is correct |
25 |
Correct |
139 ms |
17904 KB |
Output is correct |
26 |
Correct |
103 ms |
17884 KB |
Output is correct |
27 |
Correct |
106 ms |
18204 KB |
Output is correct |
28 |
Correct |
102 ms |
18176 KB |
Output is correct |
29 |
Correct |
115 ms |
18200 KB |
Output is correct |
30 |
Correct |
100 ms |
17824 KB |
Output is correct |
31 |
Correct |
107 ms |
17936 KB |
Output is correct |
32 |
Correct |
102 ms |
18176 KB |
Output is correct |
33 |
Correct |
100 ms |
17948 KB |
Output is correct |
34 |
Correct |
111 ms |
18092 KB |
Output is correct |
35 |
Correct |
108 ms |
17904 KB |
Output is correct |
36 |
Correct |
108 ms |
18176 KB |
Output is correct |
37 |
Correct |
108 ms |
17872 KB |
Output is correct |
38 |
Correct |
102 ms |
17948 KB |
Output is correct |
39 |
Correct |
109 ms |
18076 KB |
Output is correct |
40 |
Correct |
105 ms |
17784 KB |
Output is correct |
41 |
Correct |
100 ms |
18032 KB |
Output is correct |
42 |
Correct |
109 ms |
17832 KB |
Output is correct |
43 |
Runtime error |
122 ms |
36360 KB |
Execution killed with signal 11 |
44 |
Halted |
0 ms |
0 KB |
- |