Submission #281697

# Submission time Handle Problem Language Result Execution time Memory
281697 2020-08-23T10:02:51 Z williamMBDK Cubeword (CEOI19_cubeword) C++14
100 / 100
860 ms 144544 KB
#include<bits/stdc++.h>
using namespace std;
#define int long long
int M = 62;
string chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890";
vector<vector<vector<int>>> cnt (11, vector<vector<int>> (M, vector<int> (M)));
vector<int> f = {0,1,2,6,24};
int cntuni(vector<int> arr){
	map<int,int> cnt;
	for(auto e : arr) cnt[e]++;
	int res = 1;
	for(auto p : cnt) res *= f[p.second];
	return 24 / res;
}
signed main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	map<char,int> mp;
	for(int i = 0; i < M; i++) mp[chars[i]] = i;
	int N; cin >> N;
	set<string> seen;
	for(int i = 0; i < N; i++){
		string s; cin >> s;
		if(seen.count(s)) continue;
		cnt[s.length()][mp[s[0]]][mp[s[s.length() - 1]]]++;
		seen.insert(s);
		reverse(s.begin(), s.end());
		if(seen.count(s)) continue;
		cnt[s.length()][mp[s[0]]][mp[s[s.length() - 1]]]++;
		seen.insert(s);
	}
	int MOD = 998244353;
	int res = 0;
	vector<vector<vector<vector<int>>>> ans (M, vector<vector<vector<int>>> (M, vector<vector<int>> (M, vector<int> (M, -1))));
	for(int len = 3; len <= 10; len++){
		vector<vector<vector<int>>> dp (M, vector<vector<int>> (M, vector<int> (M)));
		for(int i = 0; i < M; i++){
			for(int j = i; j < M; j++){
				for(int k = j; k < M; k++){
					for(int l = 0; l < M; l++){
						dp[i][j][k] += (cnt[len][i][l] * cnt[len][j][l] * cnt[len][k][l]) % MOD;
						dp[i][j][k] %= MOD;
					}
				}
			}	
		}
		for(int i = 0; i < M; i++){
			for(int j = i; j < M; j++){
				for(int k = j; k < M; k++){
					for(int l = k; l < M; l++){
						int a = (dp[i][j][k] * dp[i][j][l] % MOD) * (dp[i][k][l] * dp[j][k][l] % MOD) % MOD;
						if(ans[i][j][k][l] != -1) a*=ans[i][j][k][l];
						else a *= (ans[i][j][k][l] = cntuni({i,j,k,l}));
						a %= MOD;
						res += a;
						res %= MOD;
					}
				}
			}	
		}
	}
	cout << res << endl;
}
# Verdict Execution time Memory Grader output
1 Correct 810 ms 142608 KB Output is correct
2 Correct 834 ms 143352 KB Output is correct
3 Correct 730 ms 143352 KB Output is correct
4 Correct 760 ms 143248 KB Output is correct
5 Correct 740 ms 143352 KB Output is correct
6 Correct 741 ms 143264 KB Output is correct
7 Correct 739 ms 143208 KB Output is correct
8 Correct 737 ms 143352 KB Output is correct
9 Correct 782 ms 143292 KB Output is correct
10 Correct 762 ms 143348 KB Output is correct
11 Correct 754 ms 143356 KB Output is correct
12 Correct 744 ms 143352 KB Output is correct
13 Correct 751 ms 143480 KB Output is correct
14 Correct 736 ms 143352 KB Output is correct
15 Correct 736 ms 143352 KB Output is correct
16 Correct 734 ms 143352 KB Output is correct
17 Correct 745 ms 143332 KB Output is correct
18 Correct 746 ms 143352 KB Output is correct
19 Correct 751 ms 143224 KB Output is correct
20 Correct 741 ms 143372 KB Output is correct
21 Correct 747 ms 143256 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 810 ms 142608 KB Output is correct
2 Correct 834 ms 143352 KB Output is correct
3 Correct 730 ms 143352 KB Output is correct
4 Correct 760 ms 143248 KB Output is correct
5 Correct 740 ms 143352 KB Output is correct
6 Correct 741 ms 143264 KB Output is correct
7 Correct 739 ms 143208 KB Output is correct
8 Correct 737 ms 143352 KB Output is correct
9 Correct 782 ms 143292 KB Output is correct
10 Correct 762 ms 143348 KB Output is correct
11 Correct 754 ms 143356 KB Output is correct
12 Correct 744 ms 143352 KB Output is correct
13 Correct 751 ms 143480 KB Output is correct
14 Correct 736 ms 143352 KB Output is correct
15 Correct 736 ms 143352 KB Output is correct
16 Correct 734 ms 143352 KB Output is correct
17 Correct 745 ms 143332 KB Output is correct
18 Correct 746 ms 143352 KB Output is correct
19 Correct 751 ms 143224 KB Output is correct
20 Correct 741 ms 143372 KB Output is correct
21 Correct 747 ms 143256 KB Output is correct
22 Correct 801 ms 143932 KB Output is correct
23 Correct 758 ms 143800 KB Output is correct
24 Correct 752 ms 144120 KB Output is correct
25 Correct 754 ms 143864 KB Output is correct
26 Correct 759 ms 143928 KB Output is correct
27 Correct 754 ms 143944 KB Output is correct
28 Correct 759 ms 143992 KB Output is correct
29 Correct 747 ms 143968 KB Output is correct
30 Correct 784 ms 143992 KB Output is correct
31 Correct 752 ms 143992 KB Output is correct
32 Correct 755 ms 143964 KB Output is correct
33 Correct 773 ms 143736 KB Output is correct
34 Correct 737 ms 143912 KB Output is correct
35 Correct 776 ms 143992 KB Output is correct
36 Correct 765 ms 143768 KB Output is correct
37 Correct 761 ms 143864 KB Output is correct
38 Correct 767 ms 143864 KB Output is correct
39 Correct 777 ms 143928 KB Output is correct
40 Correct 756 ms 143864 KB Output is correct
41 Correct 751 ms 143864 KB Output is correct
42 Correct 754 ms 143992 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 810 ms 142608 KB Output is correct
2 Correct 834 ms 143352 KB Output is correct
3 Correct 730 ms 143352 KB Output is correct
4 Correct 760 ms 143248 KB Output is correct
5 Correct 740 ms 143352 KB Output is correct
6 Correct 741 ms 143264 KB Output is correct
7 Correct 739 ms 143208 KB Output is correct
8 Correct 737 ms 143352 KB Output is correct
9 Correct 782 ms 143292 KB Output is correct
10 Correct 762 ms 143348 KB Output is correct
11 Correct 754 ms 143356 KB Output is correct
12 Correct 744 ms 143352 KB Output is correct
13 Correct 751 ms 143480 KB Output is correct
14 Correct 736 ms 143352 KB Output is correct
15 Correct 736 ms 143352 KB Output is correct
16 Correct 734 ms 143352 KB Output is correct
17 Correct 745 ms 143332 KB Output is correct
18 Correct 746 ms 143352 KB Output is correct
19 Correct 751 ms 143224 KB Output is correct
20 Correct 741 ms 143372 KB Output is correct
21 Correct 747 ms 143256 KB Output is correct
22 Correct 801 ms 143932 KB Output is correct
23 Correct 758 ms 143800 KB Output is correct
24 Correct 752 ms 144120 KB Output is correct
25 Correct 754 ms 143864 KB Output is correct
26 Correct 759 ms 143928 KB Output is correct
27 Correct 754 ms 143944 KB Output is correct
28 Correct 759 ms 143992 KB Output is correct
29 Correct 747 ms 143968 KB Output is correct
30 Correct 784 ms 143992 KB Output is correct
31 Correct 752 ms 143992 KB Output is correct
32 Correct 755 ms 143964 KB Output is correct
33 Correct 773 ms 143736 KB Output is correct
34 Correct 737 ms 143912 KB Output is correct
35 Correct 776 ms 143992 KB Output is correct
36 Correct 765 ms 143768 KB Output is correct
37 Correct 761 ms 143864 KB Output is correct
38 Correct 767 ms 143864 KB Output is correct
39 Correct 777 ms 143928 KB Output is correct
40 Correct 756 ms 143864 KB Output is correct
41 Correct 751 ms 143864 KB Output is correct
42 Correct 754 ms 143992 KB Output is correct
43 Correct 758 ms 144152 KB Output is correct
44 Correct 755 ms 144120 KB Output is correct
45 Correct 748 ms 144120 KB Output is correct
46 Correct 760 ms 143996 KB Output is correct
47 Correct 786 ms 143992 KB Output is correct
48 Correct 777 ms 144088 KB Output is correct
49 Correct 787 ms 144120 KB Output is correct
50 Correct 751 ms 143992 KB Output is correct
51 Correct 794 ms 144140 KB Output is correct
52 Correct 749 ms 144152 KB Output is correct
53 Correct 761 ms 144064 KB Output is correct
54 Correct 772 ms 144120 KB Output is correct
55 Correct 762 ms 144248 KB Output is correct
56 Correct 771 ms 143992 KB Output is correct
57 Correct 784 ms 144120 KB Output is correct
58 Correct 770 ms 144260 KB Output is correct
59 Correct 763 ms 144120 KB Output is correct
60 Correct 786 ms 144048 KB Output is correct
61 Correct 773 ms 144120 KB Output is correct
62 Correct 768 ms 144120 KB Output is correct
63 Correct 772 ms 144120 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 810 ms 142608 KB Output is correct
2 Correct 834 ms 143352 KB Output is correct
3 Correct 730 ms 143352 KB Output is correct
4 Correct 760 ms 143248 KB Output is correct
5 Correct 740 ms 143352 KB Output is correct
6 Correct 741 ms 143264 KB Output is correct
7 Correct 739 ms 143208 KB Output is correct
8 Correct 737 ms 143352 KB Output is correct
9 Correct 782 ms 143292 KB Output is correct
10 Correct 762 ms 143348 KB Output is correct
11 Correct 754 ms 143356 KB Output is correct
12 Correct 744 ms 143352 KB Output is correct
13 Correct 751 ms 143480 KB Output is correct
14 Correct 736 ms 143352 KB Output is correct
15 Correct 736 ms 143352 KB Output is correct
16 Correct 734 ms 143352 KB Output is correct
17 Correct 745 ms 143332 KB Output is correct
18 Correct 746 ms 143352 KB Output is correct
19 Correct 751 ms 143224 KB Output is correct
20 Correct 741 ms 143372 KB Output is correct
21 Correct 747 ms 143256 KB Output is correct
22 Correct 801 ms 143932 KB Output is correct
23 Correct 758 ms 143800 KB Output is correct
24 Correct 752 ms 144120 KB Output is correct
25 Correct 754 ms 143864 KB Output is correct
26 Correct 759 ms 143928 KB Output is correct
27 Correct 754 ms 143944 KB Output is correct
28 Correct 759 ms 143992 KB Output is correct
29 Correct 747 ms 143968 KB Output is correct
30 Correct 784 ms 143992 KB Output is correct
31 Correct 752 ms 143992 KB Output is correct
32 Correct 755 ms 143964 KB Output is correct
33 Correct 773 ms 143736 KB Output is correct
34 Correct 737 ms 143912 KB Output is correct
35 Correct 776 ms 143992 KB Output is correct
36 Correct 765 ms 143768 KB Output is correct
37 Correct 761 ms 143864 KB Output is correct
38 Correct 767 ms 143864 KB Output is correct
39 Correct 777 ms 143928 KB Output is correct
40 Correct 756 ms 143864 KB Output is correct
41 Correct 751 ms 143864 KB Output is correct
42 Correct 754 ms 143992 KB Output is correct
43 Correct 758 ms 144152 KB Output is correct
44 Correct 755 ms 144120 KB Output is correct
45 Correct 748 ms 144120 KB Output is correct
46 Correct 760 ms 143996 KB Output is correct
47 Correct 786 ms 143992 KB Output is correct
48 Correct 777 ms 144088 KB Output is correct
49 Correct 787 ms 144120 KB Output is correct
50 Correct 751 ms 143992 KB Output is correct
51 Correct 794 ms 144140 KB Output is correct
52 Correct 749 ms 144152 KB Output is correct
53 Correct 761 ms 144064 KB Output is correct
54 Correct 772 ms 144120 KB Output is correct
55 Correct 762 ms 144248 KB Output is correct
56 Correct 771 ms 143992 KB Output is correct
57 Correct 784 ms 144120 KB Output is correct
58 Correct 770 ms 144260 KB Output is correct
59 Correct 763 ms 144120 KB Output is correct
60 Correct 786 ms 144048 KB Output is correct
61 Correct 773 ms 144120 KB Output is correct
62 Correct 768 ms 144120 KB Output is correct
63 Correct 772 ms 144120 KB Output is correct
64 Correct 777 ms 144376 KB Output is correct
65 Correct 779 ms 144224 KB Output is correct
66 Correct 797 ms 144248 KB Output is correct
67 Correct 798 ms 144272 KB Output is correct
68 Correct 860 ms 144544 KB Output is correct
69 Correct 811 ms 144400 KB Output is correct
70 Correct 834 ms 144296 KB Output is correct
71 Correct 777 ms 144236 KB Output is correct
72 Correct 843 ms 144296 KB Output is correct
73 Correct 800 ms 144376 KB Output is correct
74 Correct 845 ms 144312 KB Output is correct
75 Correct 763 ms 144284 KB Output is correct
76 Correct 815 ms 144244 KB Output is correct
77 Correct 754 ms 144340 KB Output is correct
78 Correct 770 ms 144248 KB Output is correct
79 Correct 761 ms 144248 KB Output is correct
80 Correct 797 ms 144192 KB Output is correct
81 Correct 822 ms 144248 KB Output is correct
82 Correct 773 ms 144252 KB Output is correct
83 Correct 817 ms 144376 KB Output is correct
84 Correct 742 ms 144288 KB Output is correct