#include <bits/stdc++.h>
using namespace std;
#define int long long
#define double long double
#define FOR(i,l,r,d) for(int i=(l);i<=(r);i+=(d))
#define szof(x) ((int)(x).size())
#define vi vector<int>
#define pii pair<int,int>
#define F first
#define S second
#define pb push_back
#define eb emplace_back
#define mkp make_pair
const int INF = 2147483647;
const int LNF = INF*INF;
const int MOD = 1000000007;
const int mod = 998244353;
const double eps = 1e-12;
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops")
const int MAX = 65;
int SZ = 64; /// Subtask 4
int n;
map<char, int> char_id;
vector<string> strings[11];
set<string> edges[MAX][MAX];
int edge_cnt[MAX][MAX];
int half_cnt[MAX][MAX][MAX];
int res;
int fac[5] = {1, 1, 2, 6, 24};
int per(vi arr){
int cnt = 0;
int pv = -1;
int ret = fac[szof(arr)];
for(int i : arr){
if(i == pv){
cnt++;
}
else{
ret /= fac[cnt];
cnt = 1;
}
pv = i;
}
ret /= fac[cnt];
return ret;
}
signed main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
/// a~p -> 0~15
for(char i='a'; i<='p'; i++){
char_id[i] = i - 'a';
}
/// A~P -> 16~31
for(char i='A'; i<='P'; i++){
char_id[i] = i - 'A' + 16;
}
/// q~z -> 32~41
for(char i='q'; i<='z'; i++){
char_id[i] = i - 'a' + 16;
}
/// Q~Z -> 42~51
for(char i='Q'; i<='Z'; i++){
char_id[i] = i - 'A' + 26;
}
/// 0~9 -> 52~61
for(char i='0'; i<='9'; i++){
char_id[i] = i - '0' + 52;
}
cin>>n;
FOR(i, 1, n, 1){
string str;
cin>>str;
strings[szof(str)].pb(str);
}
/// L = len. of strings
FOR(L, 3, 10, 1){
FOR(i, 0, SZ-1, 1){
FOR(j, 0, SZ-1, 1){
edges[i][j].clear();
}
}
for(string S : strings[L]){
int u = char_id[ S[0] ];
int v = char_id[ S[L-1] ];
edges[u][v].insert(S);
reverse(S.begin(), S.end());
edges[v][u].insert(S);
}
FOR(i, 0, SZ-1, 1){
FOR(j, 0, SZ-1, 1){
edge_cnt[i][j] = szof(edges[i][j]);
}
}
/// one half
FOR(i, 0, SZ-1, 1){
FOR(j, 0, SZ-1, 1){
FOR(k, 0, SZ-1, 1){
half_cnt[i][j][k] = 0;
}
}
}
FOR(B, 0, SZ-1, 1){
FOR(D, B, SZ-1, 1){
FOR(E, D, SZ-1, 1){
FOR(A, 0, SZ-1, 1){
half_cnt[B][D][E] += edge_cnt[A][B] * edge_cnt[A][D] * edge_cnt[A][E];
half_cnt[B][D][E] %= mod;
}
// half_cnt[B][E][D] = half_cnt[D][B][E] = half_cnt[D][E][B] = half_cnt[E][B][D] = half_cnt[E][D][B] = half_cnt[B][D][E];
}
}
}
/// another half
FOR(A, 0, SZ-1, 1){
FOR(B, A, SZ-1, 1){
FOR(D, B, SZ-1, 1){
FOR(E, D, SZ-1, 1){
int val = (((half_cnt[A][B][D] * half_cnt[A][B][E]) % mod) * ((half_cnt[A][D][E] * half_cnt[B][D][E]) % mod)) % mod;
res += val * per({A, B, D, E});
res %= mod;
}
}
}
}
}
cout<<res<<'\n';
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
536 ms |
8860 KB |
Output is correct |
2 |
Correct |
509 ms |
8868 KB |
Output is correct |
3 |
Correct |
525 ms |
8896 KB |
Output is correct |
4 |
Correct |
516 ms |
8956 KB |
Output is correct |
5 |
Correct |
547 ms |
8832 KB |
Output is correct |
6 |
Correct |
520 ms |
8824 KB |
Output is correct |
7 |
Correct |
513 ms |
8844 KB |
Output is correct |
8 |
Correct |
504 ms |
8916 KB |
Output is correct |
9 |
Correct |
563 ms |
8956 KB |
Output is correct |
10 |
Correct |
524 ms |
8992 KB |
Output is correct |
11 |
Correct |
573 ms |
8808 KB |
Output is correct |
12 |
Correct |
536 ms |
8868 KB |
Output is correct |
13 |
Correct |
526 ms |
8976 KB |
Output is correct |
14 |
Correct |
539 ms |
8792 KB |
Output is correct |
15 |
Correct |
506 ms |
8976 KB |
Output is correct |
16 |
Correct |
515 ms |
8816 KB |
Output is correct |
17 |
Correct |
537 ms |
8772 KB |
Output is correct |
18 |
Correct |
540 ms |
8816 KB |
Output is correct |
19 |
Correct |
554 ms |
8824 KB |
Output is correct |
20 |
Correct |
539 ms |
8868 KB |
Output is correct |
21 |
Correct |
616 ms |
8876 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
536 ms |
8860 KB |
Output is correct |
2 |
Correct |
509 ms |
8868 KB |
Output is correct |
3 |
Correct |
525 ms |
8896 KB |
Output is correct |
4 |
Correct |
516 ms |
8956 KB |
Output is correct |
5 |
Correct |
547 ms |
8832 KB |
Output is correct |
6 |
Correct |
520 ms |
8824 KB |
Output is correct |
7 |
Correct |
513 ms |
8844 KB |
Output is correct |
8 |
Correct |
504 ms |
8916 KB |
Output is correct |
9 |
Correct |
563 ms |
8956 KB |
Output is correct |
10 |
Correct |
524 ms |
8992 KB |
Output is correct |
11 |
Correct |
573 ms |
8808 KB |
Output is correct |
12 |
Correct |
536 ms |
8868 KB |
Output is correct |
13 |
Correct |
526 ms |
8976 KB |
Output is correct |
14 |
Correct |
539 ms |
8792 KB |
Output is correct |
15 |
Correct |
506 ms |
8976 KB |
Output is correct |
16 |
Correct |
515 ms |
8816 KB |
Output is correct |
17 |
Correct |
537 ms |
8772 KB |
Output is correct |
18 |
Correct |
540 ms |
8816 KB |
Output is correct |
19 |
Correct |
554 ms |
8824 KB |
Output is correct |
20 |
Correct |
539 ms |
8868 KB |
Output is correct |
21 |
Correct |
616 ms |
8876 KB |
Output is correct |
22 |
Correct |
529 ms |
8036 KB |
Output is correct |
23 |
Correct |
561 ms |
7956 KB |
Output is correct |
24 |
Correct |
505 ms |
8132 KB |
Output is correct |
25 |
Correct |
507 ms |
7952 KB |
Output is correct |
26 |
Correct |
506 ms |
8032 KB |
Output is correct |
27 |
Correct |
500 ms |
8000 KB |
Output is correct |
28 |
Correct |
519 ms |
8028 KB |
Output is correct |
29 |
Correct |
501 ms |
7984 KB |
Output is correct |
30 |
Correct |
528 ms |
8140 KB |
Output is correct |
31 |
Correct |
532 ms |
8028 KB |
Output is correct |
32 |
Correct |
519 ms |
8016 KB |
Output is correct |
33 |
Correct |
497 ms |
8004 KB |
Output is correct |
34 |
Correct |
509 ms |
8064 KB |
Output is correct |
35 |
Correct |
522 ms |
8088 KB |
Output is correct |
36 |
Correct |
525 ms |
8036 KB |
Output is correct |
37 |
Correct |
496 ms |
8024 KB |
Output is correct |
38 |
Correct |
494 ms |
8044 KB |
Output is correct |
39 |
Correct |
495 ms |
8108 KB |
Output is correct |
40 |
Correct |
547 ms |
8024 KB |
Output is correct |
41 |
Correct |
494 ms |
7984 KB |
Output is correct |
42 |
Correct |
524 ms |
8216 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
536 ms |
8860 KB |
Output is correct |
2 |
Correct |
509 ms |
8868 KB |
Output is correct |
3 |
Correct |
525 ms |
8896 KB |
Output is correct |
4 |
Correct |
516 ms |
8956 KB |
Output is correct |
5 |
Correct |
547 ms |
8832 KB |
Output is correct |
6 |
Correct |
520 ms |
8824 KB |
Output is correct |
7 |
Correct |
513 ms |
8844 KB |
Output is correct |
8 |
Correct |
504 ms |
8916 KB |
Output is correct |
9 |
Correct |
563 ms |
8956 KB |
Output is correct |
10 |
Correct |
524 ms |
8992 KB |
Output is correct |
11 |
Correct |
573 ms |
8808 KB |
Output is correct |
12 |
Correct |
536 ms |
8868 KB |
Output is correct |
13 |
Correct |
526 ms |
8976 KB |
Output is correct |
14 |
Correct |
539 ms |
8792 KB |
Output is correct |
15 |
Correct |
506 ms |
8976 KB |
Output is correct |
16 |
Correct |
515 ms |
8816 KB |
Output is correct |
17 |
Correct |
537 ms |
8772 KB |
Output is correct |
18 |
Correct |
540 ms |
8816 KB |
Output is correct |
19 |
Correct |
554 ms |
8824 KB |
Output is correct |
20 |
Correct |
539 ms |
8868 KB |
Output is correct |
21 |
Correct |
616 ms |
8876 KB |
Output is correct |
22 |
Correct |
529 ms |
8036 KB |
Output is correct |
23 |
Correct |
561 ms |
7956 KB |
Output is correct |
24 |
Correct |
505 ms |
8132 KB |
Output is correct |
25 |
Correct |
507 ms |
7952 KB |
Output is correct |
26 |
Correct |
506 ms |
8032 KB |
Output is correct |
27 |
Correct |
500 ms |
8000 KB |
Output is correct |
28 |
Correct |
519 ms |
8028 KB |
Output is correct |
29 |
Correct |
501 ms |
7984 KB |
Output is correct |
30 |
Correct |
528 ms |
8140 KB |
Output is correct |
31 |
Correct |
532 ms |
8028 KB |
Output is correct |
32 |
Correct |
519 ms |
8016 KB |
Output is correct |
33 |
Correct |
497 ms |
8004 KB |
Output is correct |
34 |
Correct |
509 ms |
8064 KB |
Output is correct |
35 |
Correct |
522 ms |
8088 KB |
Output is correct |
36 |
Correct |
525 ms |
8036 KB |
Output is correct |
37 |
Correct |
496 ms |
8024 KB |
Output is correct |
38 |
Correct |
494 ms |
8044 KB |
Output is correct |
39 |
Correct |
495 ms |
8108 KB |
Output is correct |
40 |
Correct |
547 ms |
8024 KB |
Output is correct |
41 |
Correct |
494 ms |
7984 KB |
Output is correct |
42 |
Correct |
524 ms |
8216 KB |
Output is correct |
43 |
Correct |
547 ms |
7836 KB |
Output is correct |
44 |
Correct |
478 ms |
8732 KB |
Output is correct |
45 |
Correct |
510 ms |
8600 KB |
Output is correct |
46 |
Correct |
490 ms |
8592 KB |
Output is correct |
47 |
Correct |
552 ms |
8576 KB |
Output is correct |
48 |
Correct |
517 ms |
8612 KB |
Output is correct |
49 |
Correct |
511 ms |
8456 KB |
Output is correct |
50 |
Correct |
485 ms |
8592 KB |
Output is correct |
51 |
Correct |
487 ms |
8580 KB |
Output is correct |
52 |
Correct |
503 ms |
8720 KB |
Output is correct |
53 |
Correct |
517 ms |
8588 KB |
Output is correct |
54 |
Correct |
496 ms |
8772 KB |
Output is correct |
55 |
Correct |
516 ms |
8572 KB |
Output is correct |
56 |
Correct |
500 ms |
8960 KB |
Output is correct |
57 |
Correct |
500 ms |
8468 KB |
Output is correct |
58 |
Correct |
489 ms |
8540 KB |
Output is correct |
59 |
Correct |
498 ms |
8476 KB |
Output is correct |
60 |
Correct |
484 ms |
8588 KB |
Output is correct |
61 |
Correct |
503 ms |
8620 KB |
Output is correct |
62 |
Correct |
501 ms |
8584 KB |
Output is correct |
63 |
Correct |
546 ms |
8628 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
536 ms |
8860 KB |
Output is correct |
2 |
Correct |
509 ms |
8868 KB |
Output is correct |
3 |
Correct |
525 ms |
8896 KB |
Output is correct |
4 |
Correct |
516 ms |
8956 KB |
Output is correct |
5 |
Correct |
547 ms |
8832 KB |
Output is correct |
6 |
Correct |
520 ms |
8824 KB |
Output is correct |
7 |
Correct |
513 ms |
8844 KB |
Output is correct |
8 |
Correct |
504 ms |
8916 KB |
Output is correct |
9 |
Correct |
563 ms |
8956 KB |
Output is correct |
10 |
Correct |
524 ms |
8992 KB |
Output is correct |
11 |
Correct |
573 ms |
8808 KB |
Output is correct |
12 |
Correct |
536 ms |
8868 KB |
Output is correct |
13 |
Correct |
526 ms |
8976 KB |
Output is correct |
14 |
Correct |
539 ms |
8792 KB |
Output is correct |
15 |
Correct |
506 ms |
8976 KB |
Output is correct |
16 |
Correct |
515 ms |
8816 KB |
Output is correct |
17 |
Correct |
537 ms |
8772 KB |
Output is correct |
18 |
Correct |
540 ms |
8816 KB |
Output is correct |
19 |
Correct |
554 ms |
8824 KB |
Output is correct |
20 |
Correct |
539 ms |
8868 KB |
Output is correct |
21 |
Correct |
616 ms |
8876 KB |
Output is correct |
22 |
Correct |
529 ms |
8036 KB |
Output is correct |
23 |
Correct |
561 ms |
7956 KB |
Output is correct |
24 |
Correct |
505 ms |
8132 KB |
Output is correct |
25 |
Correct |
507 ms |
7952 KB |
Output is correct |
26 |
Correct |
506 ms |
8032 KB |
Output is correct |
27 |
Correct |
500 ms |
8000 KB |
Output is correct |
28 |
Correct |
519 ms |
8028 KB |
Output is correct |
29 |
Correct |
501 ms |
7984 KB |
Output is correct |
30 |
Correct |
528 ms |
8140 KB |
Output is correct |
31 |
Correct |
532 ms |
8028 KB |
Output is correct |
32 |
Correct |
519 ms |
8016 KB |
Output is correct |
33 |
Correct |
497 ms |
8004 KB |
Output is correct |
34 |
Correct |
509 ms |
8064 KB |
Output is correct |
35 |
Correct |
522 ms |
8088 KB |
Output is correct |
36 |
Correct |
525 ms |
8036 KB |
Output is correct |
37 |
Correct |
496 ms |
8024 KB |
Output is correct |
38 |
Correct |
494 ms |
8044 KB |
Output is correct |
39 |
Correct |
495 ms |
8108 KB |
Output is correct |
40 |
Correct |
547 ms |
8024 KB |
Output is correct |
41 |
Correct |
494 ms |
7984 KB |
Output is correct |
42 |
Correct |
524 ms |
8216 KB |
Output is correct |
43 |
Correct |
547 ms |
7836 KB |
Output is correct |
44 |
Correct |
478 ms |
8732 KB |
Output is correct |
45 |
Correct |
510 ms |
8600 KB |
Output is correct |
46 |
Correct |
490 ms |
8592 KB |
Output is correct |
47 |
Correct |
552 ms |
8576 KB |
Output is correct |
48 |
Correct |
517 ms |
8612 KB |
Output is correct |
49 |
Correct |
511 ms |
8456 KB |
Output is correct |
50 |
Correct |
485 ms |
8592 KB |
Output is correct |
51 |
Correct |
487 ms |
8580 KB |
Output is correct |
52 |
Correct |
503 ms |
8720 KB |
Output is correct |
53 |
Correct |
517 ms |
8588 KB |
Output is correct |
54 |
Correct |
496 ms |
8772 KB |
Output is correct |
55 |
Correct |
516 ms |
8572 KB |
Output is correct |
56 |
Correct |
500 ms |
8960 KB |
Output is correct |
57 |
Correct |
500 ms |
8468 KB |
Output is correct |
58 |
Correct |
489 ms |
8540 KB |
Output is correct |
59 |
Correct |
498 ms |
8476 KB |
Output is correct |
60 |
Correct |
484 ms |
8588 KB |
Output is correct |
61 |
Correct |
503 ms |
8620 KB |
Output is correct |
62 |
Correct |
501 ms |
8584 KB |
Output is correct |
63 |
Correct |
546 ms |
8628 KB |
Output is correct |
64 |
Correct |
497 ms |
8552 KB |
Output is correct |
65 |
Correct |
507 ms |
8580 KB |
Output is correct |
66 |
Correct |
478 ms |
8532 KB |
Output is correct |
67 |
Correct |
495 ms |
8676 KB |
Output is correct |
68 |
Correct |
481 ms |
8608 KB |
Output is correct |
69 |
Correct |
496 ms |
8560 KB |
Output is correct |
70 |
Correct |
479 ms |
8540 KB |
Output is correct |
71 |
Correct |
492 ms |
8660 KB |
Output is correct |
72 |
Correct |
520 ms |
8668 KB |
Output is correct |
73 |
Correct |
486 ms |
8564 KB |
Output is correct |
74 |
Correct |
487 ms |
8556 KB |
Output is correct |
75 |
Correct |
490 ms |
8780 KB |
Output is correct |
76 |
Correct |
475 ms |
8540 KB |
Output is correct |
77 |
Correct |
507 ms |
8660 KB |
Output is correct |
78 |
Correct |
480 ms |
8536 KB |
Output is correct |
79 |
Correct |
478 ms |
8564 KB |
Output is correct |
80 |
Correct |
483 ms |
8536 KB |
Output is correct |
81 |
Correct |
481 ms |
8664 KB |
Output is correct |
82 |
Correct |
524 ms |
8712 KB |
Output is correct |
83 |
Correct |
486 ms |
8588 KB |
Output is correct |
84 |
Correct |
479 ms |
8572 KB |
Output is correct |