//Sylwia Sapkowska
#include <bits/stdc++.h>
#pragma GCC optimize("O3", "unroll-loops")
using namespace std;
void __print(int x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << "'" << x << "'";}
void __print(const char *x) {cerr << '"' << x << '"';}
void __print(const string &x) {cerr << '"' << x << '"';}
void __print(bool x) {cerr << (x ? "true" : "false");}
template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ", "; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? ", " : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifdef LOCAL
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif
#define int long long
typedef pair<int, int> T;
const int oo = 1e18, oo2 = 1e9+7, K = 30;
const int mod = 998244353;
const int A = 11, mx = 52;
int mul(int a, int b){
return (a*b)%mod;
}
void add(int &a, int b){
a += b;
if (a >= mod) a-= mod;
}
void solve(){
int n; cin >> n;
vector cnt(A, vector<vector<int>>(mx, vector<int>(mx)));
set<string>a;
char cc = 'A';
for (int i = 0; i<n; i++){
string s; cin >> s;
int l = (int)s.size();
if (a.find(s) == a.end()){
a.insert(s);
cnt[l][s[0]-cc][s.back()-cc]++;
}
auto t = s;
reverse(t.begin(), t.end());
if (a.find(t) == a.end()) {
cnt[l][s.back()-cc][s[0]-cc]++;
a.insert(t);
}
}
int ans = 0;
vector zlicz(mx, vector<vector<int>>(mx, vector<int>(mx)));
for (int rep = 3; rep < A; rep++){
debug(rep);
for (int a = 0; a < mx; a++){
for (int b = 0; b < mx; b++){
for (int c = 0; c < mx; c++){
zlicz[a][b][c] = 0;
}
}
}
for (int beg = 0; beg < mx; beg++){
for (int a = 0; a < mx; a++){
for (int b = 0; b < mx; b++){
for (int c = 0; c < mx; c++){
add(zlicz[a][b][c], mul(cnt[rep][beg][a], mul(cnt[rep][beg][b], cnt[rep][beg][c])));
}
}
}
}
for (int a = 0; a < mx; a++){
for (int b = 0; b < mx; b++){
for (int c = 0; c < mx; c++){
for (int d = 0; d < mx; d++){
add(ans, mul(mul(zlicz[a][b][c], zlicz[a][c][d]), mul(zlicz[b][c][d], zlicz[a][b][d])));
}
}
}
}
}
cout << ans << "\n";
}
int32_t main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
solve();
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
546 ms |
16464 KB |
Output is correct |
2 |
Correct |
551 ms |
17232 KB |
Output is correct |
3 |
Correct |
542 ms |
17576 KB |
Output is correct |
4 |
Correct |
544 ms |
17432 KB |
Output is correct |
5 |
Correct |
534 ms |
17272 KB |
Output is correct |
6 |
Correct |
533 ms |
17384 KB |
Output is correct |
7 |
Correct |
533 ms |
17492 KB |
Output is correct |
8 |
Correct |
532 ms |
17280 KB |
Output is correct |
9 |
Correct |
550 ms |
17276 KB |
Output is correct |
10 |
Correct |
542 ms |
17488 KB |
Output is correct |
11 |
Correct |
525 ms |
17236 KB |
Output is correct |
12 |
Correct |
540 ms |
17256 KB |
Output is correct |
13 |
Correct |
542 ms |
17276 KB |
Output is correct |
14 |
Correct |
537 ms |
17136 KB |
Output is correct |
15 |
Correct |
532 ms |
17236 KB |
Output is correct |
16 |
Correct |
541 ms |
17448 KB |
Output is correct |
17 |
Correct |
539 ms |
17268 KB |
Output is correct |
18 |
Correct |
530 ms |
17156 KB |
Output is correct |
19 |
Correct |
540 ms |
17276 KB |
Output is correct |
20 |
Correct |
537 ms |
17492 KB |
Output is correct |
21 |
Correct |
528 ms |
17140 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
546 ms |
16464 KB |
Output is correct |
2 |
Correct |
551 ms |
17232 KB |
Output is correct |
3 |
Correct |
542 ms |
17576 KB |
Output is correct |
4 |
Correct |
544 ms |
17432 KB |
Output is correct |
5 |
Correct |
534 ms |
17272 KB |
Output is correct |
6 |
Correct |
533 ms |
17384 KB |
Output is correct |
7 |
Correct |
533 ms |
17492 KB |
Output is correct |
8 |
Correct |
532 ms |
17280 KB |
Output is correct |
9 |
Correct |
550 ms |
17276 KB |
Output is correct |
10 |
Correct |
542 ms |
17488 KB |
Output is correct |
11 |
Correct |
525 ms |
17236 KB |
Output is correct |
12 |
Correct |
540 ms |
17256 KB |
Output is correct |
13 |
Correct |
542 ms |
17276 KB |
Output is correct |
14 |
Correct |
537 ms |
17136 KB |
Output is correct |
15 |
Correct |
532 ms |
17236 KB |
Output is correct |
16 |
Correct |
541 ms |
17448 KB |
Output is correct |
17 |
Correct |
539 ms |
17268 KB |
Output is correct |
18 |
Correct |
530 ms |
17156 KB |
Output is correct |
19 |
Correct |
540 ms |
17276 KB |
Output is correct |
20 |
Correct |
537 ms |
17492 KB |
Output is correct |
21 |
Correct |
528 ms |
17140 KB |
Output is correct |
22 |
Correct |
540 ms |
18000 KB |
Output is correct |
23 |
Correct |
539 ms |
17832 KB |
Output is correct |
24 |
Correct |
535 ms |
17644 KB |
Output is correct |
25 |
Correct |
538 ms |
18004 KB |
Output is correct |
26 |
Correct |
542 ms |
17828 KB |
Output is correct |
27 |
Correct |
532 ms |
17748 KB |
Output is correct |
28 |
Correct |
548 ms |
17820 KB |
Output is correct |
29 |
Correct |
542 ms |
17940 KB |
Output is correct |
30 |
Correct |
536 ms |
17836 KB |
Output is correct |
31 |
Correct |
537 ms |
17836 KB |
Output is correct |
32 |
Correct |
536 ms |
18008 KB |
Output is correct |
33 |
Correct |
532 ms |
17748 KB |
Output is correct |
34 |
Correct |
534 ms |
17832 KB |
Output is correct |
35 |
Correct |
544 ms |
17836 KB |
Output is correct |
36 |
Correct |
542 ms |
17844 KB |
Output is correct |
37 |
Correct |
531 ms |
17824 KB |
Output is correct |
38 |
Correct |
554 ms |
18080 KB |
Output is correct |
39 |
Correct |
542 ms |
18000 KB |
Output is correct |
40 |
Correct |
538 ms |
17748 KB |
Output is correct |
41 |
Correct |
558 ms |
17848 KB |
Output is correct |
42 |
Correct |
547 ms |
18004 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
546 ms |
16464 KB |
Output is correct |
2 |
Correct |
551 ms |
17232 KB |
Output is correct |
3 |
Correct |
542 ms |
17576 KB |
Output is correct |
4 |
Correct |
544 ms |
17432 KB |
Output is correct |
5 |
Correct |
534 ms |
17272 KB |
Output is correct |
6 |
Correct |
533 ms |
17384 KB |
Output is correct |
7 |
Correct |
533 ms |
17492 KB |
Output is correct |
8 |
Correct |
532 ms |
17280 KB |
Output is correct |
9 |
Correct |
550 ms |
17276 KB |
Output is correct |
10 |
Correct |
542 ms |
17488 KB |
Output is correct |
11 |
Correct |
525 ms |
17236 KB |
Output is correct |
12 |
Correct |
540 ms |
17256 KB |
Output is correct |
13 |
Correct |
542 ms |
17276 KB |
Output is correct |
14 |
Correct |
537 ms |
17136 KB |
Output is correct |
15 |
Correct |
532 ms |
17236 KB |
Output is correct |
16 |
Correct |
541 ms |
17448 KB |
Output is correct |
17 |
Correct |
539 ms |
17268 KB |
Output is correct |
18 |
Correct |
530 ms |
17156 KB |
Output is correct |
19 |
Correct |
540 ms |
17276 KB |
Output is correct |
20 |
Correct |
537 ms |
17492 KB |
Output is correct |
21 |
Correct |
528 ms |
17140 KB |
Output is correct |
22 |
Correct |
540 ms |
18000 KB |
Output is correct |
23 |
Correct |
539 ms |
17832 KB |
Output is correct |
24 |
Correct |
535 ms |
17644 KB |
Output is correct |
25 |
Correct |
538 ms |
18004 KB |
Output is correct |
26 |
Correct |
542 ms |
17828 KB |
Output is correct |
27 |
Correct |
532 ms |
17748 KB |
Output is correct |
28 |
Correct |
548 ms |
17820 KB |
Output is correct |
29 |
Correct |
542 ms |
17940 KB |
Output is correct |
30 |
Correct |
536 ms |
17836 KB |
Output is correct |
31 |
Correct |
537 ms |
17836 KB |
Output is correct |
32 |
Correct |
536 ms |
18008 KB |
Output is correct |
33 |
Correct |
532 ms |
17748 KB |
Output is correct |
34 |
Correct |
534 ms |
17832 KB |
Output is correct |
35 |
Correct |
544 ms |
17836 KB |
Output is correct |
36 |
Correct |
542 ms |
17844 KB |
Output is correct |
37 |
Correct |
531 ms |
17824 KB |
Output is correct |
38 |
Correct |
554 ms |
18080 KB |
Output is correct |
39 |
Correct |
542 ms |
18000 KB |
Output is correct |
40 |
Correct |
538 ms |
17748 KB |
Output is correct |
41 |
Correct |
558 ms |
17848 KB |
Output is correct |
42 |
Correct |
547 ms |
18004 KB |
Output is correct |
43 |
Correct |
532 ms |
18004 KB |
Output is correct |
44 |
Correct |
530 ms |
18004 KB |
Output is correct |
45 |
Correct |
544 ms |
18012 KB |
Output is correct |
46 |
Correct |
540 ms |
18016 KB |
Output is correct |
47 |
Correct |
533 ms |
18012 KB |
Output is correct |
48 |
Correct |
539 ms |
18004 KB |
Output is correct |
49 |
Correct |
541 ms |
18256 KB |
Output is correct |
50 |
Correct |
544 ms |
18004 KB |
Output is correct |
51 |
Correct |
544 ms |
18020 KB |
Output is correct |
52 |
Correct |
543 ms |
18256 KB |
Output is correct |
53 |
Correct |
532 ms |
18004 KB |
Output is correct |
54 |
Correct |
547 ms |
18032 KB |
Output is correct |
55 |
Correct |
545 ms |
18196 KB |
Output is correct |
56 |
Correct |
533 ms |
18028 KB |
Output is correct |
57 |
Correct |
558 ms |
17988 KB |
Output is correct |
58 |
Correct |
535 ms |
18256 KB |
Output is correct |
59 |
Correct |
533 ms |
17852 KB |
Output is correct |
60 |
Correct |
540 ms |
18008 KB |
Output is correct |
61 |
Correct |
547 ms |
18240 KB |
Output is correct |
62 |
Correct |
540 ms |
18004 KB |
Output is correct |
63 |
Correct |
538 ms |
18012 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
546 ms |
16464 KB |
Output is correct |
2 |
Correct |
551 ms |
17232 KB |
Output is correct |
3 |
Correct |
542 ms |
17576 KB |
Output is correct |
4 |
Correct |
544 ms |
17432 KB |
Output is correct |
5 |
Correct |
534 ms |
17272 KB |
Output is correct |
6 |
Correct |
533 ms |
17384 KB |
Output is correct |
7 |
Correct |
533 ms |
17492 KB |
Output is correct |
8 |
Correct |
532 ms |
17280 KB |
Output is correct |
9 |
Correct |
550 ms |
17276 KB |
Output is correct |
10 |
Correct |
542 ms |
17488 KB |
Output is correct |
11 |
Correct |
525 ms |
17236 KB |
Output is correct |
12 |
Correct |
540 ms |
17256 KB |
Output is correct |
13 |
Correct |
542 ms |
17276 KB |
Output is correct |
14 |
Correct |
537 ms |
17136 KB |
Output is correct |
15 |
Correct |
532 ms |
17236 KB |
Output is correct |
16 |
Correct |
541 ms |
17448 KB |
Output is correct |
17 |
Correct |
539 ms |
17268 KB |
Output is correct |
18 |
Correct |
530 ms |
17156 KB |
Output is correct |
19 |
Correct |
540 ms |
17276 KB |
Output is correct |
20 |
Correct |
537 ms |
17492 KB |
Output is correct |
21 |
Correct |
528 ms |
17140 KB |
Output is correct |
22 |
Correct |
540 ms |
18000 KB |
Output is correct |
23 |
Correct |
539 ms |
17832 KB |
Output is correct |
24 |
Correct |
535 ms |
17644 KB |
Output is correct |
25 |
Correct |
538 ms |
18004 KB |
Output is correct |
26 |
Correct |
542 ms |
17828 KB |
Output is correct |
27 |
Correct |
532 ms |
17748 KB |
Output is correct |
28 |
Correct |
548 ms |
17820 KB |
Output is correct |
29 |
Correct |
542 ms |
17940 KB |
Output is correct |
30 |
Correct |
536 ms |
17836 KB |
Output is correct |
31 |
Correct |
537 ms |
17836 KB |
Output is correct |
32 |
Correct |
536 ms |
18008 KB |
Output is correct |
33 |
Correct |
532 ms |
17748 KB |
Output is correct |
34 |
Correct |
534 ms |
17832 KB |
Output is correct |
35 |
Correct |
544 ms |
17836 KB |
Output is correct |
36 |
Correct |
542 ms |
17844 KB |
Output is correct |
37 |
Correct |
531 ms |
17824 KB |
Output is correct |
38 |
Correct |
554 ms |
18080 KB |
Output is correct |
39 |
Correct |
542 ms |
18000 KB |
Output is correct |
40 |
Correct |
538 ms |
17748 KB |
Output is correct |
41 |
Correct |
558 ms |
17848 KB |
Output is correct |
42 |
Correct |
547 ms |
18004 KB |
Output is correct |
43 |
Correct |
532 ms |
18004 KB |
Output is correct |
44 |
Correct |
530 ms |
18004 KB |
Output is correct |
45 |
Correct |
544 ms |
18012 KB |
Output is correct |
46 |
Correct |
540 ms |
18016 KB |
Output is correct |
47 |
Correct |
533 ms |
18012 KB |
Output is correct |
48 |
Correct |
539 ms |
18004 KB |
Output is correct |
49 |
Correct |
541 ms |
18256 KB |
Output is correct |
50 |
Correct |
544 ms |
18004 KB |
Output is correct |
51 |
Correct |
544 ms |
18020 KB |
Output is correct |
52 |
Correct |
543 ms |
18256 KB |
Output is correct |
53 |
Correct |
532 ms |
18004 KB |
Output is correct |
54 |
Correct |
547 ms |
18032 KB |
Output is correct |
55 |
Correct |
545 ms |
18196 KB |
Output is correct |
56 |
Correct |
533 ms |
18028 KB |
Output is correct |
57 |
Correct |
558 ms |
17988 KB |
Output is correct |
58 |
Correct |
535 ms |
18256 KB |
Output is correct |
59 |
Correct |
533 ms |
17852 KB |
Output is correct |
60 |
Correct |
540 ms |
18008 KB |
Output is correct |
61 |
Correct |
547 ms |
18240 KB |
Output is correct |
62 |
Correct |
540 ms |
18004 KB |
Output is correct |
63 |
Correct |
538 ms |
18012 KB |
Output is correct |
64 |
Runtime error |
2 ms |
1116 KB |
Execution killed with signal 11 |
65 |
Halted |
0 ms |
0 KB |
- |