Submission #779853

# Submission time Handle Problem Language Result Execution time Memory
779853 2023-07-12T01:29:53 Z pedroslrey Cubeword (CEOI19_cubeword) C++17
100 / 100
793 ms 10176 KB
#include <bits/stdc++.h>

using namespace std;
using lli = long long;

const int ALPHA = 65;
const int MOD = 998244353;

int cnt[ALPHA][ALPHA];
lli prec[ALPHA][ALPHA][ALPHA];

int ctoord(char c) {
	if ('a' <= c && c <= 'z') return c - 'a';
	if ('A' <= c && c <= 'Z') return c - 'A' + 26;
	return 2*26 + c - '0';
}

lli solve(vector<string> &words) {
	if (words.empty()) return 0;
	for (int a = 0; a < ALPHA; ++a)
		for (int b = 0; b < ALPHA; ++b)
			for (int c = 0; c < ALPHA; ++c)
				prec[a][b][c] = 0;

	for (int a = 0; a < ALPHA; ++a)
		for (int b = 0; b < ALPHA; ++b)
			cnt[a][b] = 0;

	for (string w: words)
		++cnt[ctoord(w[0])][ctoord(w.back())];

	for (int a = 0; a < ALPHA; ++a)
		for (int b = a; b < ALPHA; ++b)
			for (int c = b; c < ALPHA; ++c) {
				for (int i = 0; i < ALPHA; ++i) {
					prec[a][b][c] += 1LL*cnt[a][i]*cnt[b][i]*cnt[c][i];
					prec[a][b][c] %= MOD;
				}
				//if (!words.empty() && a < 30 && b < 30 && c < 30) cerr << "prec " << (char)(a + 'a') << " " << (char)(b + 'a') << " " << (char)(c + 'a') << " " << prec[a][b][c] << "\n";
				prec[a][c][b] = prec[b][c][a] = prec[b][a][c] = prec[c][a][b] = prec[c][b][a] = prec[a][b][c];
			}

	lli ans = 0;
	for (int a = 0; a < ALPHA; ++a)
		for (int b = 0; b < ALPHA; ++b)
			for (int c = 0; c < ALPHA; ++c)
				for (int d = 0; d < ALPHA; ++d) 
					ans += prec[a][b][c]%MOD
						  *prec[a][b][d]%MOD
						  *prec[a][c][d]%MOD
						  *prec[b][c][d]%MOD;
	return ans;
}

int main() {
	int n;
	cin >> n;

	vector<vector<string>> words(11);
	for (int i = 0; i < n; ++i) {
		string s;
		cin >> s;

		words[s.size()].push_back(s);
		reverse(s.begin(), s.end());
		words[s.size()].push_back(s);
	}

	lli ans = 0;
	for (auto &xs: words) {
		sort(xs.begin(), xs.end());
		xs.erase(unique(xs.begin(), xs.end()), xs.end());

		ans += solve(xs);
		ans %= MOD;
	}

	cout << ans << "\n";
}
# Verdict Execution time Memory Grader output
1 Correct 738 ms 9608 KB Output is correct
2 Correct 732 ms 9992 KB Output is correct
3 Correct 740 ms 9968 KB Output is correct
4 Correct 733 ms 9996 KB Output is correct
5 Correct 734 ms 9960 KB Output is correct
6 Correct 740 ms 10108 KB Output is correct
7 Correct 732 ms 9844 KB Output is correct
8 Correct 727 ms 9876 KB Output is correct
9 Correct 734 ms 9960 KB Output is correct
10 Correct 732 ms 10004 KB Output is correct
11 Correct 736 ms 10176 KB Output is correct
12 Correct 735 ms 9996 KB Output is correct
13 Correct 733 ms 10024 KB Output is correct
14 Correct 730 ms 10024 KB Output is correct
15 Correct 746 ms 9968 KB Output is correct
16 Correct 774 ms 10072 KB Output is correct
17 Correct 749 ms 9968 KB Output is correct
18 Correct 759 ms 9944 KB Output is correct
19 Correct 754 ms 9868 KB Output is correct
20 Correct 763 ms 9956 KB Output is correct
21 Correct 744 ms 9884 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 738 ms 9608 KB Output is correct
2 Correct 732 ms 9992 KB Output is correct
3 Correct 740 ms 9968 KB Output is correct
4 Correct 733 ms 9996 KB Output is correct
5 Correct 734 ms 9960 KB Output is correct
6 Correct 740 ms 10108 KB Output is correct
7 Correct 732 ms 9844 KB Output is correct
8 Correct 727 ms 9876 KB Output is correct
9 Correct 734 ms 9960 KB Output is correct
10 Correct 732 ms 10004 KB Output is correct
11 Correct 736 ms 10176 KB Output is correct
12 Correct 735 ms 9996 KB Output is correct
13 Correct 733 ms 10024 KB Output is correct
14 Correct 730 ms 10024 KB Output is correct
15 Correct 746 ms 9968 KB Output is correct
16 Correct 774 ms 10072 KB Output is correct
17 Correct 749 ms 9968 KB Output is correct
18 Correct 759 ms 9944 KB Output is correct
19 Correct 754 ms 9868 KB Output is correct
20 Correct 763 ms 9956 KB Output is correct
21 Correct 744 ms 9884 KB Output is correct
22 Correct 736 ms 9664 KB Output is correct
23 Correct 755 ms 9652 KB Output is correct
24 Correct 733 ms 9944 KB Output is correct
25 Correct 739 ms 9720 KB Output is correct
26 Correct 749 ms 9628 KB Output is correct
27 Correct 737 ms 9876 KB Output is correct
28 Correct 736 ms 9652 KB Output is correct
29 Correct 743 ms 9660 KB Output is correct
30 Correct 765 ms 9656 KB Output is correct
31 Correct 728 ms 9908 KB Output is correct
32 Correct 775 ms 9600 KB Output is correct
33 Correct 740 ms 9648 KB Output is correct
34 Correct 729 ms 9732 KB Output is correct
35 Correct 742 ms 9840 KB Output is correct
36 Correct 729 ms 9728 KB Output is correct
37 Correct 736 ms 9568 KB Output is correct
38 Correct 770 ms 9924 KB Output is correct
39 Correct 771 ms 9648 KB Output is correct
40 Correct 729 ms 9760 KB Output is correct
41 Correct 751 ms 9820 KB Output is correct
42 Correct 756 ms 9708 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 738 ms 9608 KB Output is correct
2 Correct 732 ms 9992 KB Output is correct
3 Correct 740 ms 9968 KB Output is correct
4 Correct 733 ms 9996 KB Output is correct
5 Correct 734 ms 9960 KB Output is correct
6 Correct 740 ms 10108 KB Output is correct
7 Correct 732 ms 9844 KB Output is correct
8 Correct 727 ms 9876 KB Output is correct
9 Correct 734 ms 9960 KB Output is correct
10 Correct 732 ms 10004 KB Output is correct
11 Correct 736 ms 10176 KB Output is correct
12 Correct 735 ms 9996 KB Output is correct
13 Correct 733 ms 10024 KB Output is correct
14 Correct 730 ms 10024 KB Output is correct
15 Correct 746 ms 9968 KB Output is correct
16 Correct 774 ms 10072 KB Output is correct
17 Correct 749 ms 9968 KB Output is correct
18 Correct 759 ms 9944 KB Output is correct
19 Correct 754 ms 9868 KB Output is correct
20 Correct 763 ms 9956 KB Output is correct
21 Correct 744 ms 9884 KB Output is correct
22 Correct 736 ms 9664 KB Output is correct
23 Correct 755 ms 9652 KB Output is correct
24 Correct 733 ms 9944 KB Output is correct
25 Correct 739 ms 9720 KB Output is correct
26 Correct 749 ms 9628 KB Output is correct
27 Correct 737 ms 9876 KB Output is correct
28 Correct 736 ms 9652 KB Output is correct
29 Correct 743 ms 9660 KB Output is correct
30 Correct 765 ms 9656 KB Output is correct
31 Correct 728 ms 9908 KB Output is correct
32 Correct 775 ms 9600 KB Output is correct
33 Correct 740 ms 9648 KB Output is correct
34 Correct 729 ms 9732 KB Output is correct
35 Correct 742 ms 9840 KB Output is correct
36 Correct 729 ms 9728 KB Output is correct
37 Correct 736 ms 9568 KB Output is correct
38 Correct 770 ms 9924 KB Output is correct
39 Correct 771 ms 9648 KB Output is correct
40 Correct 729 ms 9760 KB Output is correct
41 Correct 751 ms 9820 KB Output is correct
42 Correct 756 ms 9708 KB Output is correct
43 Correct 743 ms 9624 KB Output is correct
44 Correct 752 ms 9604 KB Output is correct
45 Correct 739 ms 9512 KB Output is correct
46 Correct 753 ms 9620 KB Output is correct
47 Correct 737 ms 9628 KB Output is correct
48 Correct 743 ms 9620 KB Output is correct
49 Correct 730 ms 9944 KB Output is correct
50 Correct 761 ms 10016 KB Output is correct
51 Correct 750 ms 9780 KB Output is correct
52 Correct 757 ms 9560 KB Output is correct
53 Correct 738 ms 9604 KB Output is correct
54 Correct 738 ms 9632 KB Output is correct
55 Correct 739 ms 9628 KB Output is correct
56 Correct 749 ms 9628 KB Output is correct
57 Correct 767 ms 9628 KB Output is correct
58 Correct 741 ms 9612 KB Output is correct
59 Correct 761 ms 9868 KB Output is correct
60 Correct 754 ms 9992 KB Output is correct
61 Correct 757 ms 9616 KB Output is correct
62 Correct 737 ms 9888 KB Output is correct
63 Correct 782 ms 9620 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 738 ms 9608 KB Output is correct
2 Correct 732 ms 9992 KB Output is correct
3 Correct 740 ms 9968 KB Output is correct
4 Correct 733 ms 9996 KB Output is correct
5 Correct 734 ms 9960 KB Output is correct
6 Correct 740 ms 10108 KB Output is correct
7 Correct 732 ms 9844 KB Output is correct
8 Correct 727 ms 9876 KB Output is correct
9 Correct 734 ms 9960 KB Output is correct
10 Correct 732 ms 10004 KB Output is correct
11 Correct 736 ms 10176 KB Output is correct
12 Correct 735 ms 9996 KB Output is correct
13 Correct 733 ms 10024 KB Output is correct
14 Correct 730 ms 10024 KB Output is correct
15 Correct 746 ms 9968 KB Output is correct
16 Correct 774 ms 10072 KB Output is correct
17 Correct 749 ms 9968 KB Output is correct
18 Correct 759 ms 9944 KB Output is correct
19 Correct 754 ms 9868 KB Output is correct
20 Correct 763 ms 9956 KB Output is correct
21 Correct 744 ms 9884 KB Output is correct
22 Correct 736 ms 9664 KB Output is correct
23 Correct 755 ms 9652 KB Output is correct
24 Correct 733 ms 9944 KB Output is correct
25 Correct 739 ms 9720 KB Output is correct
26 Correct 749 ms 9628 KB Output is correct
27 Correct 737 ms 9876 KB Output is correct
28 Correct 736 ms 9652 KB Output is correct
29 Correct 743 ms 9660 KB Output is correct
30 Correct 765 ms 9656 KB Output is correct
31 Correct 728 ms 9908 KB Output is correct
32 Correct 775 ms 9600 KB Output is correct
33 Correct 740 ms 9648 KB Output is correct
34 Correct 729 ms 9732 KB Output is correct
35 Correct 742 ms 9840 KB Output is correct
36 Correct 729 ms 9728 KB Output is correct
37 Correct 736 ms 9568 KB Output is correct
38 Correct 770 ms 9924 KB Output is correct
39 Correct 771 ms 9648 KB Output is correct
40 Correct 729 ms 9760 KB Output is correct
41 Correct 751 ms 9820 KB Output is correct
42 Correct 756 ms 9708 KB Output is correct
43 Correct 743 ms 9624 KB Output is correct
44 Correct 752 ms 9604 KB Output is correct
45 Correct 739 ms 9512 KB Output is correct
46 Correct 753 ms 9620 KB Output is correct
47 Correct 737 ms 9628 KB Output is correct
48 Correct 743 ms 9620 KB Output is correct
49 Correct 730 ms 9944 KB Output is correct
50 Correct 761 ms 10016 KB Output is correct
51 Correct 750 ms 9780 KB Output is correct
52 Correct 757 ms 9560 KB Output is correct
53 Correct 738 ms 9604 KB Output is correct
54 Correct 738 ms 9632 KB Output is correct
55 Correct 739 ms 9628 KB Output is correct
56 Correct 749 ms 9628 KB Output is correct
57 Correct 767 ms 9628 KB Output is correct
58 Correct 741 ms 9612 KB Output is correct
59 Correct 761 ms 9868 KB Output is correct
60 Correct 754 ms 9992 KB Output is correct
61 Correct 757 ms 9616 KB Output is correct
62 Correct 737 ms 9888 KB Output is correct
63 Correct 782 ms 9620 KB Output is correct
64 Correct 781 ms 9624 KB Output is correct
65 Correct 793 ms 9620 KB Output is correct
66 Correct 780 ms 9616 KB Output is correct
67 Correct 730 ms 9876 KB Output is correct
68 Correct 730 ms 9608 KB Output is correct
69 Correct 727 ms 10004 KB Output is correct
70 Correct 735 ms 9620 KB Output is correct
71 Correct 745 ms 9620 KB Output is correct
72 Correct 730 ms 9612 KB Output is correct
73 Correct 742 ms 9616 KB Output is correct
74 Correct 739 ms 9940 KB Output is correct
75 Correct 736 ms 9868 KB Output is correct
76 Correct 728 ms 9748 KB Output is correct
77 Correct 726 ms 9620 KB Output is correct
78 Correct 739 ms 9616 KB Output is correct
79 Correct 744 ms 9620 KB Output is correct
80 Correct 739 ms 9876 KB Output is correct
81 Correct 738 ms 9876 KB Output is correct
82 Correct 737 ms 9864 KB Output is correct
83 Correct 729 ms 9988 KB Output is correct
84 Correct 734 ms 9956 KB Output is correct