#include <iostream>
#include <cstring>
#include <vector>
#include <algorithm>
using namespace std;
const int MOD = 998244353;
int char_to_int(char c){
if('a' <= c && c <= 'z'){
return c - 'a';
}
else if('A' <= c && c <= 'Z'){
return c - 'A' + 'z' - 'a' + 1;
}
else{
return c - '0' + 'Z' - 'A' + 'z' - 'a' + 2;
}
}
int n;
string s;
vector<string> stuff[15];
int words[62][62];
int cnt[62][62][62];
int fact[] = {1,1,2,6,24};
int get_cnt(vector<int> v){
int lst = -1;
int cnt = 0;
int ans = fact[4];
for(auto it:v){
if(lst == it){
cnt++;
}
else{
ans /= fact[cnt];
lst = it;
cnt = 1;
}
}
ans /= fact[cnt];
return ans;
}
int solve(vector<string> &stuff){
if(stuff.empty()){
return 0;
}
sort(stuff.begin(),stuff.end());
stuff.resize(unique(stuff.begin(),stuff.end()) - stuff.begin());
memset(words,0,sizeof(words));
for(int i = 0;i < 62;i++){
for(int j = i;j < 62;j++){
for(int k = j;k < 62;k++){
cnt[i][j][k] = 0;
}
}
}
for(auto it:stuff){
words[char_to_int(it[0])][char_to_int(it.back())]++;
}
for(int a = 0;a < 62;a++){
for(int b = a;b < 62;b++){
for(int c = b;c < 62;c++){
for(int d = 0;d < 62;d++){
cnt[a][b][c] = (cnt[a][b][c] + 1LL * words[a][d] * words[b][d] * words[c][d]) % MOD;
}
}
}
}
int ans = 0;
for(int a = 0;a < 62;a++){
for(int b = a;b < 62;b++){
for(int c = b;c < 62;c++){
for(int d = c;d < 62;d++){
int num = get_cnt({a,b,c,d});
ans = (ans + (num + 0LL) * ((1LL * cnt[a][b][c] * cnt[a][b][d] % MOD) * (1LL * cnt[a][c][d] * cnt[b][c][d] % MOD) % MOD)) % MOD;
}
}
}
}
return ans;
}
int main(){
cin >> n;
for(int i = 1;i <= n;i++){
cin >> s;
stuff[s.size()].push_back(s);
reverse(s.begin(),s.end());
stuff[s.size()].push_back(s);
}
int ans = 0;
for(int i = 3;i <= 10;i++){
ans += solve(stuff[i]);
if(ans >= MOD){
ans -= MOD;
}
}
cout << ans;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
509 ms |
7732 KB |
Output is correct |
2 |
Correct |
501 ms |
8648 KB |
Output is correct |
3 |
Correct |
508 ms |
8376 KB |
Output is correct |
4 |
Correct |
490 ms |
8660 KB |
Output is correct |
5 |
Correct |
493 ms |
8692 KB |
Output is correct |
6 |
Correct |
503 ms |
8508 KB |
Output is correct |
7 |
Correct |
501 ms |
8700 KB |
Output is correct |
8 |
Correct |
504 ms |
8716 KB |
Output is correct |
9 |
Correct |
491 ms |
8636 KB |
Output is correct |
10 |
Correct |
512 ms |
8572 KB |
Output is correct |
11 |
Correct |
511 ms |
8488 KB |
Output is correct |
12 |
Correct |
504 ms |
8528 KB |
Output is correct |
13 |
Correct |
499 ms |
8656 KB |
Output is correct |
14 |
Correct |
518 ms |
8604 KB |
Output is correct |
15 |
Correct |
521 ms |
8544 KB |
Output is correct |
16 |
Correct |
514 ms |
8580 KB |
Output is correct |
17 |
Correct |
508 ms |
8580 KB |
Output is correct |
18 |
Correct |
489 ms |
8612 KB |
Output is correct |
19 |
Correct |
503 ms |
8564 KB |
Output is correct |
20 |
Correct |
490 ms |
8412 KB |
Output is correct |
21 |
Correct |
512 ms |
8556 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
509 ms |
7732 KB |
Output is correct |
2 |
Correct |
501 ms |
8648 KB |
Output is correct |
3 |
Correct |
508 ms |
8376 KB |
Output is correct |
4 |
Correct |
490 ms |
8660 KB |
Output is correct |
5 |
Correct |
493 ms |
8692 KB |
Output is correct |
6 |
Correct |
503 ms |
8508 KB |
Output is correct |
7 |
Correct |
501 ms |
8700 KB |
Output is correct |
8 |
Correct |
504 ms |
8716 KB |
Output is correct |
9 |
Correct |
491 ms |
8636 KB |
Output is correct |
10 |
Correct |
512 ms |
8572 KB |
Output is correct |
11 |
Correct |
511 ms |
8488 KB |
Output is correct |
12 |
Correct |
504 ms |
8528 KB |
Output is correct |
13 |
Correct |
499 ms |
8656 KB |
Output is correct |
14 |
Correct |
518 ms |
8604 KB |
Output is correct |
15 |
Correct |
521 ms |
8544 KB |
Output is correct |
16 |
Correct |
514 ms |
8580 KB |
Output is correct |
17 |
Correct |
508 ms |
8580 KB |
Output is correct |
18 |
Correct |
489 ms |
8612 KB |
Output is correct |
19 |
Correct |
503 ms |
8564 KB |
Output is correct |
20 |
Correct |
490 ms |
8412 KB |
Output is correct |
21 |
Correct |
512 ms |
8556 KB |
Output is correct |
22 |
Correct |
503 ms |
8192 KB |
Output is correct |
23 |
Correct |
472 ms |
8300 KB |
Output is correct |
24 |
Correct |
485 ms |
8164 KB |
Output is correct |
25 |
Correct |
489 ms |
8292 KB |
Output is correct |
26 |
Correct |
479 ms |
8180 KB |
Output is correct |
27 |
Correct |
507 ms |
8312 KB |
Output is correct |
28 |
Correct |
501 ms |
8400 KB |
Output is correct |
29 |
Correct |
480 ms |
8628 KB |
Output is correct |
30 |
Correct |
473 ms |
8632 KB |
Output is correct |
31 |
Correct |
486 ms |
8304 KB |
Output is correct |
32 |
Correct |
475 ms |
8276 KB |
Output is correct |
33 |
Correct |
490 ms |
8488 KB |
Output is correct |
34 |
Correct |
466 ms |
8464 KB |
Output is correct |
35 |
Correct |
482 ms |
8276 KB |
Output is correct |
36 |
Correct |
497 ms |
8416 KB |
Output is correct |
37 |
Correct |
517 ms |
8368 KB |
Output is correct |
38 |
Correct |
502 ms |
8360 KB |
Output is correct |
39 |
Correct |
490 ms |
8412 KB |
Output is correct |
40 |
Correct |
508 ms |
8360 KB |
Output is correct |
41 |
Correct |
502 ms |
8628 KB |
Output is correct |
42 |
Correct |
503 ms |
8336 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
509 ms |
7732 KB |
Output is correct |
2 |
Correct |
501 ms |
8648 KB |
Output is correct |
3 |
Correct |
508 ms |
8376 KB |
Output is correct |
4 |
Correct |
490 ms |
8660 KB |
Output is correct |
5 |
Correct |
493 ms |
8692 KB |
Output is correct |
6 |
Correct |
503 ms |
8508 KB |
Output is correct |
7 |
Correct |
501 ms |
8700 KB |
Output is correct |
8 |
Correct |
504 ms |
8716 KB |
Output is correct |
9 |
Correct |
491 ms |
8636 KB |
Output is correct |
10 |
Correct |
512 ms |
8572 KB |
Output is correct |
11 |
Correct |
511 ms |
8488 KB |
Output is correct |
12 |
Correct |
504 ms |
8528 KB |
Output is correct |
13 |
Correct |
499 ms |
8656 KB |
Output is correct |
14 |
Correct |
518 ms |
8604 KB |
Output is correct |
15 |
Correct |
521 ms |
8544 KB |
Output is correct |
16 |
Correct |
514 ms |
8580 KB |
Output is correct |
17 |
Correct |
508 ms |
8580 KB |
Output is correct |
18 |
Correct |
489 ms |
8612 KB |
Output is correct |
19 |
Correct |
503 ms |
8564 KB |
Output is correct |
20 |
Correct |
490 ms |
8412 KB |
Output is correct |
21 |
Correct |
512 ms |
8556 KB |
Output is correct |
22 |
Correct |
503 ms |
8192 KB |
Output is correct |
23 |
Correct |
472 ms |
8300 KB |
Output is correct |
24 |
Correct |
485 ms |
8164 KB |
Output is correct |
25 |
Correct |
489 ms |
8292 KB |
Output is correct |
26 |
Correct |
479 ms |
8180 KB |
Output is correct |
27 |
Correct |
507 ms |
8312 KB |
Output is correct |
28 |
Correct |
501 ms |
8400 KB |
Output is correct |
29 |
Correct |
480 ms |
8628 KB |
Output is correct |
30 |
Correct |
473 ms |
8632 KB |
Output is correct |
31 |
Correct |
486 ms |
8304 KB |
Output is correct |
32 |
Correct |
475 ms |
8276 KB |
Output is correct |
33 |
Correct |
490 ms |
8488 KB |
Output is correct |
34 |
Correct |
466 ms |
8464 KB |
Output is correct |
35 |
Correct |
482 ms |
8276 KB |
Output is correct |
36 |
Correct |
497 ms |
8416 KB |
Output is correct |
37 |
Correct |
517 ms |
8368 KB |
Output is correct |
38 |
Correct |
502 ms |
8360 KB |
Output is correct |
39 |
Correct |
490 ms |
8412 KB |
Output is correct |
40 |
Correct |
508 ms |
8360 KB |
Output is correct |
41 |
Correct |
502 ms |
8628 KB |
Output is correct |
42 |
Correct |
503 ms |
8336 KB |
Output is correct |
43 |
Correct |
494 ms |
8360 KB |
Output is correct |
44 |
Correct |
469 ms |
8260 KB |
Output is correct |
45 |
Correct |
505 ms |
8172 KB |
Output is correct |
46 |
Correct |
485 ms |
8436 KB |
Output is correct |
47 |
Correct |
484 ms |
8508 KB |
Output is correct |
48 |
Correct |
482 ms |
8500 KB |
Output is correct |
49 |
Correct |
506 ms |
8172 KB |
Output is correct |
50 |
Correct |
487 ms |
8276 KB |
Output is correct |
51 |
Correct |
471 ms |
8228 KB |
Output is correct |
52 |
Correct |
494 ms |
8232 KB |
Output is correct |
53 |
Correct |
490 ms |
8268 KB |
Output is correct |
54 |
Correct |
504 ms |
8292 KB |
Output is correct |
55 |
Correct |
496 ms |
8364 KB |
Output is correct |
56 |
Correct |
489 ms |
8452 KB |
Output is correct |
57 |
Correct |
496 ms |
8500 KB |
Output is correct |
58 |
Correct |
509 ms |
8220 KB |
Output is correct |
59 |
Correct |
496 ms |
8292 KB |
Output is correct |
60 |
Correct |
504 ms |
8484 KB |
Output is correct |
61 |
Correct |
483 ms |
8352 KB |
Output is correct |
62 |
Correct |
477 ms |
8312 KB |
Output is correct |
63 |
Correct |
480 ms |
8436 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
509 ms |
7732 KB |
Output is correct |
2 |
Correct |
501 ms |
8648 KB |
Output is correct |
3 |
Correct |
508 ms |
8376 KB |
Output is correct |
4 |
Correct |
490 ms |
8660 KB |
Output is correct |
5 |
Correct |
493 ms |
8692 KB |
Output is correct |
6 |
Correct |
503 ms |
8508 KB |
Output is correct |
7 |
Correct |
501 ms |
8700 KB |
Output is correct |
8 |
Correct |
504 ms |
8716 KB |
Output is correct |
9 |
Correct |
491 ms |
8636 KB |
Output is correct |
10 |
Correct |
512 ms |
8572 KB |
Output is correct |
11 |
Correct |
511 ms |
8488 KB |
Output is correct |
12 |
Correct |
504 ms |
8528 KB |
Output is correct |
13 |
Correct |
499 ms |
8656 KB |
Output is correct |
14 |
Correct |
518 ms |
8604 KB |
Output is correct |
15 |
Correct |
521 ms |
8544 KB |
Output is correct |
16 |
Correct |
514 ms |
8580 KB |
Output is correct |
17 |
Correct |
508 ms |
8580 KB |
Output is correct |
18 |
Correct |
489 ms |
8612 KB |
Output is correct |
19 |
Correct |
503 ms |
8564 KB |
Output is correct |
20 |
Correct |
490 ms |
8412 KB |
Output is correct |
21 |
Correct |
512 ms |
8556 KB |
Output is correct |
22 |
Correct |
503 ms |
8192 KB |
Output is correct |
23 |
Correct |
472 ms |
8300 KB |
Output is correct |
24 |
Correct |
485 ms |
8164 KB |
Output is correct |
25 |
Correct |
489 ms |
8292 KB |
Output is correct |
26 |
Correct |
479 ms |
8180 KB |
Output is correct |
27 |
Correct |
507 ms |
8312 KB |
Output is correct |
28 |
Correct |
501 ms |
8400 KB |
Output is correct |
29 |
Correct |
480 ms |
8628 KB |
Output is correct |
30 |
Correct |
473 ms |
8632 KB |
Output is correct |
31 |
Correct |
486 ms |
8304 KB |
Output is correct |
32 |
Correct |
475 ms |
8276 KB |
Output is correct |
33 |
Correct |
490 ms |
8488 KB |
Output is correct |
34 |
Correct |
466 ms |
8464 KB |
Output is correct |
35 |
Correct |
482 ms |
8276 KB |
Output is correct |
36 |
Correct |
497 ms |
8416 KB |
Output is correct |
37 |
Correct |
517 ms |
8368 KB |
Output is correct |
38 |
Correct |
502 ms |
8360 KB |
Output is correct |
39 |
Correct |
490 ms |
8412 KB |
Output is correct |
40 |
Correct |
508 ms |
8360 KB |
Output is correct |
41 |
Correct |
502 ms |
8628 KB |
Output is correct |
42 |
Correct |
503 ms |
8336 KB |
Output is correct |
43 |
Correct |
494 ms |
8360 KB |
Output is correct |
44 |
Correct |
469 ms |
8260 KB |
Output is correct |
45 |
Correct |
505 ms |
8172 KB |
Output is correct |
46 |
Correct |
485 ms |
8436 KB |
Output is correct |
47 |
Correct |
484 ms |
8508 KB |
Output is correct |
48 |
Correct |
482 ms |
8500 KB |
Output is correct |
49 |
Correct |
506 ms |
8172 KB |
Output is correct |
50 |
Correct |
487 ms |
8276 KB |
Output is correct |
51 |
Correct |
471 ms |
8228 KB |
Output is correct |
52 |
Correct |
494 ms |
8232 KB |
Output is correct |
53 |
Correct |
490 ms |
8268 KB |
Output is correct |
54 |
Correct |
504 ms |
8292 KB |
Output is correct |
55 |
Correct |
496 ms |
8364 KB |
Output is correct |
56 |
Correct |
489 ms |
8452 KB |
Output is correct |
57 |
Correct |
496 ms |
8500 KB |
Output is correct |
58 |
Correct |
509 ms |
8220 KB |
Output is correct |
59 |
Correct |
496 ms |
8292 KB |
Output is correct |
60 |
Correct |
504 ms |
8484 KB |
Output is correct |
61 |
Correct |
483 ms |
8352 KB |
Output is correct |
62 |
Correct |
477 ms |
8312 KB |
Output is correct |
63 |
Correct |
480 ms |
8436 KB |
Output is correct |
64 |
Correct |
492 ms |
8492 KB |
Output is correct |
65 |
Correct |
484 ms |
8604 KB |
Output is correct |
66 |
Correct |
482 ms |
8312 KB |
Output is correct |
67 |
Correct |
495 ms |
8424 KB |
Output is correct |
68 |
Correct |
503 ms |
8244 KB |
Output is correct |
69 |
Correct |
494 ms |
8240 KB |
Output is correct |
70 |
Correct |
490 ms |
8420 KB |
Output is correct |
71 |
Correct |
483 ms |
8224 KB |
Output is correct |
72 |
Correct |
509 ms |
8308 KB |
Output is correct |
73 |
Correct |
493 ms |
8256 KB |
Output is correct |
74 |
Correct |
501 ms |
8460 KB |
Output is correct |
75 |
Correct |
492 ms |
8364 KB |
Output is correct |
76 |
Correct |
505 ms |
8236 KB |
Output is correct |
77 |
Correct |
477 ms |
8536 KB |
Output is correct |
78 |
Correct |
482 ms |
8248 KB |
Output is correct |
79 |
Correct |
496 ms |
8192 KB |
Output is correct |
80 |
Correct |
482 ms |
8172 KB |
Output is correct |
81 |
Correct |
466 ms |
8108 KB |
Output is correct |
82 |
Correct |
485 ms |
8624 KB |
Output is correct |
83 |
Correct |
475 ms |
8356 KB |
Output is correct |
84 |
Correct |
505 ms |
8168 KB |
Output is correct |