# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
349239 | 2021-01-17T07:51:10 Z | Bill_00 | Cubeword (CEOI19_cubeword) | C++14 | 1032 ms | 39732 KB |
#include <bits/stdc++.h> #define N 100001 #define MOD 998244353 #define ll long long #define pb push_back const int M=62; using namespace std; unordered_map<string,bool>um; string a[N]; ll cnt[M][M][11],dp[M][M][M][11]; ll ans; int main(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n; cin >> n; for(int i=1;i<=n;++i){ cin >> a[i]; int k=a[i].size(); char s=a[i][0],t=a[i][k-1]; int ss,tt; if('a'<=s && s<='z') ss=s-'a'; if('A'<=s && s<='Z') ss=s-'A'+26; if('0'<=s && s<='9') ss=s-'0'+52; if('a'<=t && t<='z') tt=t-'a'; if('A'<=t && t<='Z') tt=t-'A'+26; if('0'<=t && t<='9') tt=t-'0'+52; if(um[a[i]]==0) cnt[ss][tt][k]++; um[a[i]]=1; reverse(a[i].begin(),a[i].end()); if(um[a[i]]==0){ um[a[i]]=1; cnt[tt][ss][k]++; } } for(int i=0;i<M;++i){ for(int j=0;j<M;++j){ for(int k=0;k<M;++k){ for(int p=0;p<M;++p){ for(int num=3;num<=10;++num){ ll res=1; res*=cnt[i][p][num]; res*=cnt[j][p][num]; if(res>=MOD)res%=MOD; res*=cnt[k][p][num]; dp[i][j][k][num]+=res; if(dp[i][j][k][num]>=MOD) dp[i][j][k][num]%=MOD; } } } } } for(int i=0;i<M;++i){ for(int j=0;j<M;++j){ for(int k=0;k<M;++k){ for(int p=0;p<M;++p){ for(int num=3;num<=10;++num){ ll res=1; res*=dp[i][j][k][num]; res*=dp[i][j][p][num]; if(res>=MOD)res%=MOD; res*=dp[i][k][p][num]; if(res>=MOD)res%=MOD; res*=dp[j][k][p][num]; ans+=res; if(ans>=MOD)ans%=MOD; } } } } } cout << ans; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 731 ms | 38580 KB | Output is correct |
2 | Correct | 733 ms | 38452 KB | Output is correct |
3 | Correct | 751 ms | 38600 KB | Output is correct |
4 | Correct | 730 ms | 38472 KB | Output is correct |
5 | Correct | 737 ms | 38452 KB | Output is correct |
6 | Correct | 752 ms | 38452 KB | Output is correct |
7 | Correct | 727 ms | 38672 KB | Output is correct |
8 | Correct | 726 ms | 38580 KB | Output is correct |
9 | Correct | 734 ms | 38472 KB | Output is correct |
10 | Correct | 744 ms | 38708 KB | Output is correct |
11 | Correct | 723 ms | 38468 KB | Output is correct |
12 | Correct | 732 ms | 38452 KB | Output is correct |
13 | Correct | 728 ms | 38580 KB | Output is correct |
14 | Correct | 730 ms | 38580 KB | Output is correct |
15 | Correct | 745 ms | 38560 KB | Output is correct |
16 | Correct | 732 ms | 38452 KB | Output is correct |
17 | Correct | 733 ms | 38452 KB | Output is correct |
18 | Correct | 750 ms | 38640 KB | Output is correct |
19 | Correct | 736 ms | 38580 KB | Output is correct |
20 | Correct | 743 ms | 38580 KB | Output is correct |
21 | Correct | 726 ms | 38580 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 731 ms | 38580 KB | Output is correct |
2 | Correct | 733 ms | 38452 KB | Output is correct |
3 | Correct | 751 ms | 38600 KB | Output is correct |
4 | Correct | 730 ms | 38472 KB | Output is correct |
5 | Correct | 737 ms | 38452 KB | Output is correct |
6 | Correct | 752 ms | 38452 KB | Output is correct |
7 | Correct | 727 ms | 38672 KB | Output is correct |
8 | Correct | 726 ms | 38580 KB | Output is correct |
9 | Correct | 734 ms | 38472 KB | Output is correct |
10 | Correct | 744 ms | 38708 KB | Output is correct |
11 | Correct | 723 ms | 38468 KB | Output is correct |
12 | Correct | 732 ms | 38452 KB | Output is correct |
13 | Correct | 728 ms | 38580 KB | Output is correct |
14 | Correct | 730 ms | 38580 KB | Output is correct |
15 | Correct | 745 ms | 38560 KB | Output is correct |
16 | Correct | 732 ms | 38452 KB | Output is correct |
17 | Correct | 733 ms | 38452 KB | Output is correct |
18 | Correct | 750 ms | 38640 KB | Output is correct |
19 | Correct | 736 ms | 38580 KB | Output is correct |
20 | Correct | 743 ms | 38580 KB | Output is correct |
21 | Correct | 726 ms | 38580 KB | Output is correct |
22 | Correct | 751 ms | 38964 KB | Output is correct |
23 | Correct | 738 ms | 38928 KB | Output is correct |
24 | Correct | 754 ms | 38964 KB | Output is correct |
25 | Correct | 723 ms | 38964 KB | Output is correct |
26 | Correct | 726 ms | 38964 KB | Output is correct |
27 | Correct | 751 ms | 39092 KB | Output is correct |
28 | Correct | 761 ms | 39152 KB | Output is correct |
29 | Correct | 737 ms | 38964 KB | Output is correct |
30 | Correct | 741 ms | 38964 KB | Output is correct |
31 | Correct | 734 ms | 39092 KB | Output is correct |
32 | Correct | 772 ms | 39036 KB | Output is correct |
33 | Correct | 732 ms | 39092 KB | Output is correct |
34 | Correct | 736 ms | 38964 KB | Output is correct |
35 | Correct | 737 ms | 38964 KB | Output is correct |
36 | Correct | 727 ms | 39028 KB | Output is correct |
37 | Correct | 738 ms | 38964 KB | Output is correct |
38 | Correct | 729 ms | 39220 KB | Output is correct |
39 | Correct | 737 ms | 38964 KB | Output is correct |
40 | Correct | 730 ms | 39060 KB | Output is correct |
41 | Correct | 743 ms | 38964 KB | Output is correct |
42 | Correct | 773 ms | 39092 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 731 ms | 38580 KB | Output is correct |
2 | Correct | 733 ms | 38452 KB | Output is correct |
3 | Correct | 751 ms | 38600 KB | Output is correct |
4 | Correct | 730 ms | 38472 KB | Output is correct |
5 | Correct | 737 ms | 38452 KB | Output is correct |
6 | Correct | 752 ms | 38452 KB | Output is correct |
7 | Correct | 727 ms | 38672 KB | Output is correct |
8 | Correct | 726 ms | 38580 KB | Output is correct |
9 | Correct | 734 ms | 38472 KB | Output is correct |
10 | Correct | 744 ms | 38708 KB | Output is correct |
11 | Correct | 723 ms | 38468 KB | Output is correct |
12 | Correct | 732 ms | 38452 KB | Output is correct |
13 | Correct | 728 ms | 38580 KB | Output is correct |
14 | Correct | 730 ms | 38580 KB | Output is correct |
15 | Correct | 745 ms | 38560 KB | Output is correct |
16 | Correct | 732 ms | 38452 KB | Output is correct |
17 | Correct | 733 ms | 38452 KB | Output is correct |
18 | Correct | 750 ms | 38640 KB | Output is correct |
19 | Correct | 736 ms | 38580 KB | Output is correct |
20 | Correct | 743 ms | 38580 KB | Output is correct |
21 | Correct | 726 ms | 38580 KB | Output is correct |
22 | Correct | 751 ms | 38964 KB | Output is correct |
23 | Correct | 738 ms | 38928 KB | Output is correct |
24 | Correct | 754 ms | 38964 KB | Output is correct |
25 | Correct | 723 ms | 38964 KB | Output is correct |
26 | Correct | 726 ms | 38964 KB | Output is correct |
27 | Correct | 751 ms | 39092 KB | Output is correct |
28 | Correct | 761 ms | 39152 KB | Output is correct |
29 | Correct | 737 ms | 38964 KB | Output is correct |
30 | Correct | 741 ms | 38964 KB | Output is correct |
31 | Correct | 734 ms | 39092 KB | Output is correct |
32 | Correct | 772 ms | 39036 KB | Output is correct |
33 | Correct | 732 ms | 39092 KB | Output is correct |
34 | Correct | 736 ms | 38964 KB | Output is correct |
35 | Correct | 737 ms | 38964 KB | Output is correct |
36 | Correct | 727 ms | 39028 KB | Output is correct |
37 | Correct | 738 ms | 38964 KB | Output is correct |
38 | Correct | 729 ms | 39220 KB | Output is correct |
39 | Correct | 737 ms | 38964 KB | Output is correct |
40 | Correct | 730 ms | 39060 KB | Output is correct |
41 | Correct | 743 ms | 38964 KB | Output is correct |
42 | Correct | 773 ms | 39092 KB | Output is correct |
43 | Correct | 766 ms | 39220 KB | Output is correct |
44 | Correct | 823 ms | 39220 KB | Output is correct |
45 | Correct | 763 ms | 39220 KB | Output is correct |
46 | Correct | 773 ms | 39348 KB | Output is correct |
47 | Correct | 804 ms | 39348 KB | Output is correct |
48 | Correct | 771 ms | 39364 KB | Output is correct |
49 | Correct | 792 ms | 39336 KB | Output is correct |
50 | Correct | 774 ms | 39476 KB | Output is correct |
51 | Correct | 843 ms | 39220 KB | Output is correct |
52 | Correct | 770 ms | 39220 KB | Output is correct |
53 | Correct | 766 ms | 39220 KB | Output is correct |
54 | Correct | 780 ms | 39220 KB | Output is correct |
55 | Correct | 783 ms | 39220 KB | Output is correct |
56 | Correct | 784 ms | 39220 KB | Output is correct |
57 | Correct | 814 ms | 39220 KB | Output is correct |
58 | Correct | 774 ms | 39220 KB | Output is correct |
59 | Correct | 778 ms | 39296 KB | Output is correct |
60 | Correct | 771 ms | 39220 KB | Output is correct |
61 | Correct | 780 ms | 39220 KB | Output is correct |
62 | Correct | 767 ms | 39152 KB | Output is correct |
63 | Correct | 761 ms | 39348 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 731 ms | 38580 KB | Output is correct |
2 | Correct | 733 ms | 38452 KB | Output is correct |
3 | Correct | 751 ms | 38600 KB | Output is correct |
4 | Correct | 730 ms | 38472 KB | Output is correct |
5 | Correct | 737 ms | 38452 KB | Output is correct |
6 | Correct | 752 ms | 38452 KB | Output is correct |
7 | Correct | 727 ms | 38672 KB | Output is correct |
8 | Correct | 726 ms | 38580 KB | Output is correct |
9 | Correct | 734 ms | 38472 KB | Output is correct |
10 | Correct | 744 ms | 38708 KB | Output is correct |
11 | Correct | 723 ms | 38468 KB | Output is correct |
12 | Correct | 732 ms | 38452 KB | Output is correct |
13 | Correct | 728 ms | 38580 KB | Output is correct |
14 | Correct | 730 ms | 38580 KB | Output is correct |
15 | Correct | 745 ms | 38560 KB | Output is correct |
16 | Correct | 732 ms | 38452 KB | Output is correct |
17 | Correct | 733 ms | 38452 KB | Output is correct |
18 | Correct | 750 ms | 38640 KB | Output is correct |
19 | Correct | 736 ms | 38580 KB | Output is correct |
20 | Correct | 743 ms | 38580 KB | Output is correct |
21 | Correct | 726 ms | 38580 KB | Output is correct |
22 | Correct | 751 ms | 38964 KB | Output is correct |
23 | Correct | 738 ms | 38928 KB | Output is correct |
24 | Correct | 754 ms | 38964 KB | Output is correct |
25 | Correct | 723 ms | 38964 KB | Output is correct |
26 | Correct | 726 ms | 38964 KB | Output is correct |
27 | Correct | 751 ms | 39092 KB | Output is correct |
28 | Correct | 761 ms | 39152 KB | Output is correct |
29 | Correct | 737 ms | 38964 KB | Output is correct |
30 | Correct | 741 ms | 38964 KB | Output is correct |
31 | Correct | 734 ms | 39092 KB | Output is correct |
32 | Correct | 772 ms | 39036 KB | Output is correct |
33 | Correct | 732 ms | 39092 KB | Output is correct |
34 | Correct | 736 ms | 38964 KB | Output is correct |
35 | Correct | 737 ms | 38964 KB | Output is correct |
36 | Correct | 727 ms | 39028 KB | Output is correct |
37 | Correct | 738 ms | 38964 KB | Output is correct |
38 | Correct | 729 ms | 39220 KB | Output is correct |
39 | Correct | 737 ms | 38964 KB | Output is correct |
40 | Correct | 730 ms | 39060 KB | Output is correct |
41 | Correct | 743 ms | 38964 KB | Output is correct |
42 | Correct | 773 ms | 39092 KB | Output is correct |
43 | Correct | 766 ms | 39220 KB | Output is correct |
44 | Correct | 823 ms | 39220 KB | Output is correct |
45 | Correct | 763 ms | 39220 KB | Output is correct |
46 | Correct | 773 ms | 39348 KB | Output is correct |
47 | Correct | 804 ms | 39348 KB | Output is correct |
48 | Correct | 771 ms | 39364 KB | Output is correct |
49 | Correct | 792 ms | 39336 KB | Output is correct |
50 | Correct | 774 ms | 39476 KB | Output is correct |
51 | Correct | 843 ms | 39220 KB | Output is correct |
52 | Correct | 770 ms | 39220 KB | Output is correct |
53 | Correct | 766 ms | 39220 KB | Output is correct |
54 | Correct | 780 ms | 39220 KB | Output is correct |
55 | Correct | 783 ms | 39220 KB | Output is correct |
56 | Correct | 784 ms | 39220 KB | Output is correct |
57 | Correct | 814 ms | 39220 KB | Output is correct |
58 | Correct | 774 ms | 39220 KB | Output is correct |
59 | Correct | 778 ms | 39296 KB | Output is correct |
60 | Correct | 771 ms | 39220 KB | Output is correct |
61 | Correct | 780 ms | 39220 KB | Output is correct |
62 | Correct | 767 ms | 39152 KB | Output is correct |
63 | Correct | 761 ms | 39348 KB | Output is correct |
64 | Correct | 1012 ms | 39540 KB | Output is correct |
65 | Correct | 1026 ms | 39604 KB | Output is correct |
66 | Correct | 1012 ms | 39604 KB | Output is correct |
67 | Correct | 1006 ms | 39604 KB | Output is correct |
68 | Correct | 1018 ms | 39596 KB | Output is correct |
69 | Correct | 1014 ms | 39732 KB | Output is correct |
70 | Correct | 1006 ms | 39604 KB | Output is correct |
71 | Correct | 1028 ms | 39604 KB | Output is correct |
72 | Correct | 1029 ms | 39604 KB | Output is correct |
73 | Correct | 1004 ms | 39604 KB | Output is correct |
74 | Correct | 1004 ms | 39604 KB | Output is correct |
75 | Correct | 1010 ms | 39604 KB | Output is correct |
76 | Correct | 1006 ms | 39604 KB | Output is correct |
77 | Correct | 1008 ms | 39732 KB | Output is correct |
78 | Correct | 1006 ms | 39604 KB | Output is correct |
79 | Correct | 1012 ms | 39604 KB | Output is correct |
80 | Correct | 1012 ms | 39604 KB | Output is correct |
81 | Correct | 1018 ms | 39604 KB | Output is correct |
82 | Correct | 1032 ms | 39604 KB | Output is correct |
83 | Correct | 1025 ms | 39604 KB | Output is correct |
84 | Correct | 1008 ms | 39624 KB | Output is correct |