#include<bits/stdc++.h>
#pragma GCC optimize("O3")
#pragma GCC target("sse4")
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef long double ld;
#define endl '\n'
#define pb push_back
#define all(x) x.begin(), x.end()
#define F first
#define S second
#define fast_io ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define debug(x) cerr<<#x<<" "<<x<<endl;
ll mod = 998244353;
const int N = 1e6+23, S= 63;
ll ans=0;
ll num[S][S][S];
ll cnt[11][S][S];
set<string> st[11];
int n;
ll power(ll a, ll b){
ll ans=1;
a%=mod;
while(b){
if(b&1) ans=ans*a%mod;
b>>=1;
a=a*a%mod;
}
return ans;
}
int get(char c){
if(c>='a' && c<='z'){
int t=c-'a';
return t;
}
if(c>='A' && c<='Z'){
int t=c-'A';
t+=26;
return t;
}
int t=c-'0';
t+=52;
return t;
}
ll za(int a, int b, int c, int d){
if(a==b && b==c && c==d) return 1;
if(a!=b && b==c && c==d) return 4;
if(a==b && b==c && c!=d) return 4;
if(a==b && b!=c && c==d) return 6;
if(a!=b && b!=c && c==d) return 12;
if(a!=b && b==c && c!=d) return 12;
if(a==b && b!=c && c!=d) return 12;
if(a!=b && b!=c && c!=d) return 24;
}
int main()
{
fast_io
cin>>n;
for (int i=0; i<n; i++){
string s; cin>>s;
st[s.size()].insert(s);
reverse(all(s));
st[s.size()].insert(s);
}
for (int i=3; i<=10; i++){
for (string s : st[i]){
char c=s.back();
int t=get(c);
c=s[0];
int r=get(c);
cnt[i][r][t]++;
}
for (int a=0; a<S; a++) for (int b=a; b<S; b++) for (int c=b; c<S; c++) num[a][b][c]=0;
for (int a=0; a<S; a++) for (int b=a; b<S; b++) for (int c=b; c<S; c++) for (int x=0; x<S; x++)num[a][b][c]=(num[a][b][c]+cnt[i][x][a]*cnt[i][x][b]%mod*cnt[i][x][c]%mod)%mod;
for (int a=0; a<S; a++) for (int b=a; b<S; b++) for (int c=b; c<S; c++) for (int d=c; d<S; d++) {
ll temp = (num[a][b][c]*num[a][b][d]%mod*num[a][c][d]%mod*num[b][c][d]%mod)%mod;
temp=temp*za(a, b, c, d)%mod;
ans=(ans+temp)%mod;
}
}
cout<<ans<<endl;
}
Compilation message
cubeword.cpp: In function 'll za(int, int, int, int)':
cubeword.cpp:66:1: warning: control reaches end of non-void function [-Wreturn-type]
66 | }
| ^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
518 ms |
17784 KB |
Output is correct |
2 |
Correct |
493 ms |
17764 KB |
Output is correct |
3 |
Correct |
502 ms |
17628 KB |
Output is correct |
4 |
Correct |
494 ms |
17752 KB |
Output is correct |
5 |
Correct |
502 ms |
17780 KB |
Output is correct |
6 |
Correct |
499 ms |
17772 KB |
Output is correct |
7 |
Correct |
501 ms |
18000 KB |
Output is correct |
8 |
Correct |
503 ms |
18004 KB |
Output is correct |
9 |
Correct |
500 ms |
17764 KB |
Output is correct |
10 |
Correct |
511 ms |
17784 KB |
Output is correct |
11 |
Correct |
495 ms |
17748 KB |
Output is correct |
12 |
Correct |
515 ms |
17708 KB |
Output is correct |
13 |
Correct |
502 ms |
17784 KB |
Output is correct |
14 |
Correct |
493 ms |
17776 KB |
Output is correct |
15 |
Correct |
503 ms |
17744 KB |
Output is correct |
16 |
Correct |
500 ms |
18000 KB |
Output is correct |
17 |
Correct |
504 ms |
17664 KB |
Output is correct |
18 |
Correct |
504 ms |
17756 KB |
Output is correct |
19 |
Correct |
499 ms |
18000 KB |
Output is correct |
20 |
Correct |
492 ms |
17748 KB |
Output is correct |
21 |
Correct |
509 ms |
18004 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
518 ms |
17784 KB |
Output is correct |
2 |
Correct |
493 ms |
17764 KB |
Output is correct |
3 |
Correct |
502 ms |
17628 KB |
Output is correct |
4 |
Correct |
494 ms |
17752 KB |
Output is correct |
5 |
Correct |
502 ms |
17780 KB |
Output is correct |
6 |
Correct |
499 ms |
17772 KB |
Output is correct |
7 |
Correct |
501 ms |
18000 KB |
Output is correct |
8 |
Correct |
503 ms |
18004 KB |
Output is correct |
9 |
Correct |
500 ms |
17764 KB |
Output is correct |
10 |
Correct |
511 ms |
17784 KB |
Output is correct |
11 |
Correct |
495 ms |
17748 KB |
Output is correct |
12 |
Correct |
515 ms |
17708 KB |
Output is correct |
13 |
Correct |
502 ms |
17784 KB |
Output is correct |
14 |
Correct |
493 ms |
17776 KB |
Output is correct |
15 |
Correct |
503 ms |
17744 KB |
Output is correct |
16 |
Correct |
500 ms |
18000 KB |
Output is correct |
17 |
Correct |
504 ms |
17664 KB |
Output is correct |
18 |
Correct |
504 ms |
17756 KB |
Output is correct |
19 |
Correct |
499 ms |
18000 KB |
Output is correct |
20 |
Correct |
492 ms |
17748 KB |
Output is correct |
21 |
Correct |
509 ms |
18004 KB |
Output is correct |
22 |
Correct |
509 ms |
18456 KB |
Output is correct |
23 |
Correct |
500 ms |
18512 KB |
Output is correct |
24 |
Correct |
507 ms |
18516 KB |
Output is correct |
25 |
Correct |
501 ms |
18256 KB |
Output is correct |
26 |
Correct |
504 ms |
18260 KB |
Output is correct |
27 |
Correct |
503 ms |
18512 KB |
Output is correct |
28 |
Correct |
503 ms |
18436 KB |
Output is correct |
29 |
Correct |
503 ms |
17684 KB |
Output is correct |
30 |
Correct |
499 ms |
17676 KB |
Output is correct |
31 |
Correct |
508 ms |
17676 KB |
Output is correct |
32 |
Correct |
520 ms |
17720 KB |
Output is correct |
33 |
Correct |
500 ms |
17916 KB |
Output is correct |
34 |
Correct |
492 ms |
17680 KB |
Output is correct |
35 |
Correct |
511 ms |
17648 KB |
Output is correct |
36 |
Correct |
500 ms |
17664 KB |
Output is correct |
37 |
Correct |
528 ms |
17676 KB |
Output is correct |
38 |
Correct |
499 ms |
17740 KB |
Output is correct |
39 |
Correct |
503 ms |
17488 KB |
Output is correct |
40 |
Correct |
502 ms |
17476 KB |
Output is correct |
41 |
Correct |
529 ms |
17748 KB |
Output is correct |
42 |
Correct |
503 ms |
17684 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
518 ms |
17784 KB |
Output is correct |
2 |
Correct |
493 ms |
17764 KB |
Output is correct |
3 |
Correct |
502 ms |
17628 KB |
Output is correct |
4 |
Correct |
494 ms |
17752 KB |
Output is correct |
5 |
Correct |
502 ms |
17780 KB |
Output is correct |
6 |
Correct |
499 ms |
17772 KB |
Output is correct |
7 |
Correct |
501 ms |
18000 KB |
Output is correct |
8 |
Correct |
503 ms |
18004 KB |
Output is correct |
9 |
Correct |
500 ms |
17764 KB |
Output is correct |
10 |
Correct |
511 ms |
17784 KB |
Output is correct |
11 |
Correct |
495 ms |
17748 KB |
Output is correct |
12 |
Correct |
515 ms |
17708 KB |
Output is correct |
13 |
Correct |
502 ms |
17784 KB |
Output is correct |
14 |
Correct |
493 ms |
17776 KB |
Output is correct |
15 |
Correct |
503 ms |
17744 KB |
Output is correct |
16 |
Correct |
500 ms |
18000 KB |
Output is correct |
17 |
Correct |
504 ms |
17664 KB |
Output is correct |
18 |
Correct |
504 ms |
17756 KB |
Output is correct |
19 |
Correct |
499 ms |
18000 KB |
Output is correct |
20 |
Correct |
492 ms |
17748 KB |
Output is correct |
21 |
Correct |
509 ms |
18004 KB |
Output is correct |
22 |
Correct |
509 ms |
18456 KB |
Output is correct |
23 |
Correct |
500 ms |
18512 KB |
Output is correct |
24 |
Correct |
507 ms |
18516 KB |
Output is correct |
25 |
Correct |
501 ms |
18256 KB |
Output is correct |
26 |
Correct |
504 ms |
18260 KB |
Output is correct |
27 |
Correct |
503 ms |
18512 KB |
Output is correct |
28 |
Correct |
503 ms |
18436 KB |
Output is correct |
29 |
Correct |
503 ms |
17684 KB |
Output is correct |
30 |
Correct |
499 ms |
17676 KB |
Output is correct |
31 |
Correct |
508 ms |
17676 KB |
Output is correct |
32 |
Correct |
520 ms |
17720 KB |
Output is correct |
33 |
Correct |
500 ms |
17916 KB |
Output is correct |
34 |
Correct |
492 ms |
17680 KB |
Output is correct |
35 |
Correct |
511 ms |
17648 KB |
Output is correct |
36 |
Correct |
500 ms |
17664 KB |
Output is correct |
37 |
Correct |
528 ms |
17676 KB |
Output is correct |
38 |
Correct |
499 ms |
17740 KB |
Output is correct |
39 |
Correct |
503 ms |
17488 KB |
Output is correct |
40 |
Correct |
502 ms |
17476 KB |
Output is correct |
41 |
Correct |
529 ms |
17748 KB |
Output is correct |
42 |
Correct |
503 ms |
17684 KB |
Output is correct |
43 |
Correct |
520 ms |
17884 KB |
Output is correct |
44 |
Correct |
530 ms |
17936 KB |
Output is correct |
45 |
Correct |
544 ms |
18124 KB |
Output is correct |
46 |
Correct |
518 ms |
17916 KB |
Output is correct |
47 |
Correct |
541 ms |
17920 KB |
Output is correct |
48 |
Correct |
526 ms |
17804 KB |
Output is correct |
49 |
Correct |
527 ms |
17884 KB |
Output is correct |
50 |
Correct |
534 ms |
17972 KB |
Output is correct |
51 |
Correct |
535 ms |
17916 KB |
Output is correct |
52 |
Correct |
528 ms |
17816 KB |
Output is correct |
53 |
Correct |
508 ms |
17920 KB |
Output is correct |
54 |
Correct |
502 ms |
17744 KB |
Output is correct |
55 |
Correct |
510 ms |
17748 KB |
Output is correct |
56 |
Correct |
518 ms |
17920 KB |
Output is correct |
57 |
Correct |
506 ms |
17748 KB |
Output is correct |
58 |
Correct |
510 ms |
17876 KB |
Output is correct |
59 |
Correct |
508 ms |
18256 KB |
Output is correct |
60 |
Correct |
527 ms |
17912 KB |
Output is correct |
61 |
Correct |
509 ms |
18076 KB |
Output is correct |
62 |
Correct |
504 ms |
17908 KB |
Output is correct |
63 |
Correct |
503 ms |
17744 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
518 ms |
17784 KB |
Output is correct |
2 |
Correct |
493 ms |
17764 KB |
Output is correct |
3 |
Correct |
502 ms |
17628 KB |
Output is correct |
4 |
Correct |
494 ms |
17752 KB |
Output is correct |
5 |
Correct |
502 ms |
17780 KB |
Output is correct |
6 |
Correct |
499 ms |
17772 KB |
Output is correct |
7 |
Correct |
501 ms |
18000 KB |
Output is correct |
8 |
Correct |
503 ms |
18004 KB |
Output is correct |
9 |
Correct |
500 ms |
17764 KB |
Output is correct |
10 |
Correct |
511 ms |
17784 KB |
Output is correct |
11 |
Correct |
495 ms |
17748 KB |
Output is correct |
12 |
Correct |
515 ms |
17708 KB |
Output is correct |
13 |
Correct |
502 ms |
17784 KB |
Output is correct |
14 |
Correct |
493 ms |
17776 KB |
Output is correct |
15 |
Correct |
503 ms |
17744 KB |
Output is correct |
16 |
Correct |
500 ms |
18000 KB |
Output is correct |
17 |
Correct |
504 ms |
17664 KB |
Output is correct |
18 |
Correct |
504 ms |
17756 KB |
Output is correct |
19 |
Correct |
499 ms |
18000 KB |
Output is correct |
20 |
Correct |
492 ms |
17748 KB |
Output is correct |
21 |
Correct |
509 ms |
18004 KB |
Output is correct |
22 |
Correct |
509 ms |
18456 KB |
Output is correct |
23 |
Correct |
500 ms |
18512 KB |
Output is correct |
24 |
Correct |
507 ms |
18516 KB |
Output is correct |
25 |
Correct |
501 ms |
18256 KB |
Output is correct |
26 |
Correct |
504 ms |
18260 KB |
Output is correct |
27 |
Correct |
503 ms |
18512 KB |
Output is correct |
28 |
Correct |
503 ms |
18436 KB |
Output is correct |
29 |
Correct |
503 ms |
17684 KB |
Output is correct |
30 |
Correct |
499 ms |
17676 KB |
Output is correct |
31 |
Correct |
508 ms |
17676 KB |
Output is correct |
32 |
Correct |
520 ms |
17720 KB |
Output is correct |
33 |
Correct |
500 ms |
17916 KB |
Output is correct |
34 |
Correct |
492 ms |
17680 KB |
Output is correct |
35 |
Correct |
511 ms |
17648 KB |
Output is correct |
36 |
Correct |
500 ms |
17664 KB |
Output is correct |
37 |
Correct |
528 ms |
17676 KB |
Output is correct |
38 |
Correct |
499 ms |
17740 KB |
Output is correct |
39 |
Correct |
503 ms |
17488 KB |
Output is correct |
40 |
Correct |
502 ms |
17476 KB |
Output is correct |
41 |
Correct |
529 ms |
17748 KB |
Output is correct |
42 |
Correct |
503 ms |
17684 KB |
Output is correct |
43 |
Correct |
520 ms |
17884 KB |
Output is correct |
44 |
Correct |
530 ms |
17936 KB |
Output is correct |
45 |
Correct |
544 ms |
18124 KB |
Output is correct |
46 |
Correct |
518 ms |
17916 KB |
Output is correct |
47 |
Correct |
541 ms |
17920 KB |
Output is correct |
48 |
Correct |
526 ms |
17804 KB |
Output is correct |
49 |
Correct |
527 ms |
17884 KB |
Output is correct |
50 |
Correct |
534 ms |
17972 KB |
Output is correct |
51 |
Correct |
535 ms |
17916 KB |
Output is correct |
52 |
Correct |
528 ms |
17816 KB |
Output is correct |
53 |
Correct |
508 ms |
17920 KB |
Output is correct |
54 |
Correct |
502 ms |
17744 KB |
Output is correct |
55 |
Correct |
510 ms |
17748 KB |
Output is correct |
56 |
Correct |
518 ms |
17920 KB |
Output is correct |
57 |
Correct |
506 ms |
17748 KB |
Output is correct |
58 |
Correct |
510 ms |
17876 KB |
Output is correct |
59 |
Correct |
508 ms |
18256 KB |
Output is correct |
60 |
Correct |
527 ms |
17912 KB |
Output is correct |
61 |
Correct |
509 ms |
18076 KB |
Output is correct |
62 |
Correct |
504 ms |
17908 KB |
Output is correct |
63 |
Correct |
503 ms |
17744 KB |
Output is correct |
64 |
Correct |
532 ms |
18204 KB |
Output is correct |
65 |
Correct |
537 ms |
19128 KB |
Output is correct |
66 |
Correct |
525 ms |
18908 KB |
Output is correct |
67 |
Correct |
560 ms |
18824 KB |
Output is correct |
68 |
Correct |
535 ms |
19028 KB |
Output is correct |
69 |
Correct |
533 ms |
18740 KB |
Output is correct |
70 |
Correct |
539 ms |
18908 KB |
Output is correct |
71 |
Correct |
526 ms |
18908 KB |
Output is correct |
72 |
Correct |
528 ms |
18772 KB |
Output is correct |
73 |
Correct |
528 ms |
18680 KB |
Output is correct |
74 |
Correct |
528 ms |
18912 KB |
Output is correct |
75 |
Correct |
520 ms |
18772 KB |
Output is correct |
76 |
Correct |
537 ms |
18856 KB |
Output is correct |
77 |
Correct |
528 ms |
18908 KB |
Output is correct |
78 |
Correct |
525 ms |
18772 KB |
Output is correct |
79 |
Correct |
525 ms |
18768 KB |
Output is correct |
80 |
Correct |
526 ms |
19024 KB |
Output is correct |
81 |
Correct |
527 ms |
18768 KB |
Output is correct |
82 |
Correct |
519 ms |
18772 KB |
Output is correct |
83 |
Correct |
526 ms |
18916 KB |
Output is correct |
84 |
Correct |
533 ms |
19088 KB |
Output is correct |