# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
660094 | 2022-11-20T10:57:37 Z | 600Mihnea | Cubeword (CEOI19_cubeword) | C++17 | 74 ms | 9040 KB |
bool home = 0; #include <bits/stdc++.h> using namespace std; const int MODULO = 998244353; int get_char_id(char ch) { assert(('a' <= ch && ch <= 'z') || ('A' <= ch && ch <= 'Z') || ('0' <= ch && ch <= '9')); if ('a' <= ch && ch <= 'z') { return ch - 'a'; } if ('A' <= ch && ch <= 'Z') { return 1 + get_char_id('z') + ch - 'A'; } return 1 + get_char_id('Z') + ch - '0'; } const int MAX_WORD_LENGTH = 10; ///const int ALPHABET_SIZE = 2 * 26 + 10; const int ALPHABET_SIZE = 16; vector<string> words[MAX_WORD_LENGTH + 1]; int cnt_words[ALPHABET_SIZE][ALPHABET_SIZE]; int cnt3[ALPHABET_SIZE][ALPHABET_SIZE][ALPHABET_SIZE]; int main() { if (home == 0) { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); } else { freopen ("input.txt", "r", stdin); } { size_t num_samples; cin >> num_samples; for (size_t sample_index = 0; sample_index < num_samples; sample_index++) { string word; cin >> word; words[word.size()].push_back(word); } } int solution = 0; for (size_t word_length = 1; word_length <= MAX_WORD_LENGTH; word_length++) { if (words[word_length].empty()) { continue; } size_t word_count = words[word_length].size(); for (size_t word_index = 0; word_index < word_count; word_index++) { string reverse_word = words[word_length][word_index]; reverse(reverse_word.begin(), reverse_word.end()); words[word_length].push_back(reverse_word); } sort(words[word_length].begin(), words[word_length].end()); words[word_length].resize(unique(words[word_length].begin(), words[word_length].end()) - words[word_length].begin()); word_count = words[word_length].size(); for (size_t first_letter = 0; first_letter < ALPHABET_SIZE; first_letter++) { for (size_t last_letter = 0; last_letter < ALPHABET_SIZE; last_letter++) { cnt_words[first_letter][last_letter] = 0; } } for (size_t word_index = 0; word_index < word_count; word_index++) { cnt_words[get_char_id(words[word_length][word_index][0])][get_char_id(words[word_length][word_index].back())]++; } for (size_t a = 0; a < ALPHABET_SIZE; a++) { for (size_t b = 0; b < ALPHABET_SIZE; b++) { for (size_t c = 0; c < ALPHABET_SIZE; c++) { cnt3[a][b][c] = 0; for (size_t d = 0; d < ALPHABET_SIZE; d++) { cnt3[a][b][c] = (cnt3[a][b][c] + 1LL * cnt_words[d][a] * cnt_words[d][b] * cnt_words[d][c]) % MODULO; } } } } for (size_t a = 0; a < ALPHABET_SIZE; a++) { for (size_t b = 0; b < ALPHABET_SIZE; b++) { for (size_t c = 0; c < ALPHABET_SIZE; c++) { for (size_t d = 0; d < ALPHABET_SIZE; d++) { int x1 = cnt3[a][b][c]; int x2 = cnt3[a][d][b]; int x3 = cnt3[a][c][d]; int x4 = cnt3[b][c][d]; solution = (solution + 1LL * x1 * x2 % MODULO * x3 % MODULO * x4) % MODULO; /* solution = (solution + 1LL * cnt_words[a][d] * cnt_words[a][f] * cnt_words[b][d] % MODULO * cnt_words[b][e] * cnt_words[c][f] * cnt_words[c][e] % MODULO * cnt3[a][b][c] % MODULO * cnt3[d][e][f]) % MODULO; }*/ } } } } } cout << solution << "\n"; return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 64 ms | 7964 KB | Output is correct |
2 | Correct | 60 ms | 7916 KB | Output is correct |
3 | Correct | 58 ms | 7824 KB | Output is correct |
4 | Correct | 59 ms | 7820 KB | Output is correct |
5 | Correct | 66 ms | 7932 KB | Output is correct |
6 | Correct | 61 ms | 7824 KB | Output is correct |
7 | Correct | 61 ms | 7864 KB | Output is correct |
8 | Correct | 60 ms | 7864 KB | Output is correct |
9 | Correct | 60 ms | 7900 KB | Output is correct |
10 | Correct | 59 ms | 7868 KB | Output is correct |
11 | Correct | 60 ms | 7796 KB | Output is correct |
12 | Correct | 57 ms | 7820 KB | Output is correct |
13 | Correct | 61 ms | 7896 KB | Output is correct |
14 | Correct | 61 ms | 7776 KB | Output is correct |
15 | Correct | 59 ms | 7772 KB | Output is correct |
16 | Correct | 61 ms | 7864 KB | Output is correct |
17 | Correct | 60 ms | 7756 KB | Output is correct |
18 | Correct | 62 ms | 7908 KB | Output is correct |
19 | Correct | 60 ms | 7868 KB | Output is correct |
20 | Correct | 61 ms | 7876 KB | Output is correct |
21 | Correct | 74 ms | 7944 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 64 ms | 7964 KB | Output is correct |
2 | Correct | 60 ms | 7916 KB | Output is correct |
3 | Correct | 58 ms | 7824 KB | Output is correct |
4 | Correct | 59 ms | 7820 KB | Output is correct |
5 | Correct | 66 ms | 7932 KB | Output is correct |
6 | Correct | 61 ms | 7824 KB | Output is correct |
7 | Correct | 61 ms | 7864 KB | Output is correct |
8 | Correct | 60 ms | 7864 KB | Output is correct |
9 | Correct | 60 ms | 7900 KB | Output is correct |
10 | Correct | 59 ms | 7868 KB | Output is correct |
11 | Correct | 60 ms | 7796 KB | Output is correct |
12 | Correct | 57 ms | 7820 KB | Output is correct |
13 | Correct | 61 ms | 7896 KB | Output is correct |
14 | Correct | 61 ms | 7776 KB | Output is correct |
15 | Correct | 59 ms | 7772 KB | Output is correct |
16 | Correct | 61 ms | 7864 KB | Output is correct |
17 | Correct | 60 ms | 7756 KB | Output is correct |
18 | Correct | 62 ms | 7908 KB | Output is correct |
19 | Correct | 60 ms | 7868 KB | Output is correct |
20 | Correct | 61 ms | 7876 KB | Output is correct |
21 | Correct | 74 ms | 7944 KB | Output is correct |
22 | Correct | 58 ms | 6884 KB | Output is correct |
23 | Correct | 59 ms | 7732 KB | Output is correct |
24 | Correct | 58 ms | 7628 KB | Output is correct |
25 | Correct | 64 ms | 7660 KB | Output is correct |
26 | Correct | 59 ms | 7744 KB | Output is correct |
27 | Correct | 58 ms | 7628 KB | Output is correct |
28 | Correct | 58 ms | 7748 KB | Output is correct |
29 | Correct | 65 ms | 7604 KB | Output is correct |
30 | Correct | 59 ms | 7756 KB | Output is correct |
31 | Correct | 60 ms | 7676 KB | Output is correct |
32 | Correct | 58 ms | 7664 KB | Output is correct |
33 | Correct | 63 ms | 7752 KB | Output is correct |
34 | Correct | 58 ms | 7724 KB | Output is correct |
35 | Correct | 59 ms | 7844 KB | Output is correct |
36 | Correct | 60 ms | 7788 KB | Output is correct |
37 | Correct | 57 ms | 7672 KB | Output is correct |
38 | Correct | 58 ms | 7676 KB | Output is correct |
39 | Correct | 60 ms | 7636 KB | Output is correct |
40 | Correct | 58 ms | 7620 KB | Output is correct |
41 | Correct | 58 ms | 7632 KB | Output is correct |
42 | Correct | 58 ms | 8196 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 64 ms | 7964 KB | Output is correct |
2 | Correct | 60 ms | 7916 KB | Output is correct |
3 | Correct | 58 ms | 7824 KB | Output is correct |
4 | Correct | 59 ms | 7820 KB | Output is correct |
5 | Correct | 66 ms | 7932 KB | Output is correct |
6 | Correct | 61 ms | 7824 KB | Output is correct |
7 | Correct | 61 ms | 7864 KB | Output is correct |
8 | Correct | 60 ms | 7864 KB | Output is correct |
9 | Correct | 60 ms | 7900 KB | Output is correct |
10 | Correct | 59 ms | 7868 KB | Output is correct |
11 | Correct | 60 ms | 7796 KB | Output is correct |
12 | Correct | 57 ms | 7820 KB | Output is correct |
13 | Correct | 61 ms | 7896 KB | Output is correct |
14 | Correct | 61 ms | 7776 KB | Output is correct |
15 | Correct | 59 ms | 7772 KB | Output is correct |
16 | Correct | 61 ms | 7864 KB | Output is correct |
17 | Correct | 60 ms | 7756 KB | Output is correct |
18 | Correct | 62 ms | 7908 KB | Output is correct |
19 | Correct | 60 ms | 7868 KB | Output is correct |
20 | Correct | 61 ms | 7876 KB | Output is correct |
21 | Correct | 74 ms | 7944 KB | Output is correct |
22 | Correct | 58 ms | 6884 KB | Output is correct |
23 | Correct | 59 ms | 7732 KB | Output is correct |
24 | Correct | 58 ms | 7628 KB | Output is correct |
25 | Correct | 64 ms | 7660 KB | Output is correct |
26 | Correct | 59 ms | 7744 KB | Output is correct |
27 | Correct | 58 ms | 7628 KB | Output is correct |
28 | Correct | 58 ms | 7748 KB | Output is correct |
29 | Correct | 65 ms | 7604 KB | Output is correct |
30 | Correct | 59 ms | 7756 KB | Output is correct |
31 | Correct | 60 ms | 7676 KB | Output is correct |
32 | Correct | 58 ms | 7664 KB | Output is correct |
33 | Correct | 63 ms | 7752 KB | Output is correct |
34 | Correct | 58 ms | 7724 KB | Output is correct |
35 | Correct | 59 ms | 7844 KB | Output is correct |
36 | Correct | 60 ms | 7788 KB | Output is correct |
37 | Correct | 57 ms | 7672 KB | Output is correct |
38 | Correct | 58 ms | 7676 KB | Output is correct |
39 | Correct | 60 ms | 7636 KB | Output is correct |
40 | Correct | 58 ms | 7620 KB | Output is correct |
41 | Correct | 58 ms | 7632 KB | Output is correct |
42 | Correct | 58 ms | 8196 KB | Output is correct |
43 | Runtime error | 19 ms | 9040 KB | Execution killed with signal 11 |
44 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 64 ms | 7964 KB | Output is correct |
2 | Correct | 60 ms | 7916 KB | Output is correct |
3 | Correct | 58 ms | 7824 KB | Output is correct |
4 | Correct | 59 ms | 7820 KB | Output is correct |
5 | Correct | 66 ms | 7932 KB | Output is correct |
6 | Correct | 61 ms | 7824 KB | Output is correct |
7 | Correct | 61 ms | 7864 KB | Output is correct |
8 | Correct | 60 ms | 7864 KB | Output is correct |
9 | Correct | 60 ms | 7900 KB | Output is correct |
10 | Correct | 59 ms | 7868 KB | Output is correct |
11 | Correct | 60 ms | 7796 KB | Output is correct |
12 | Correct | 57 ms | 7820 KB | Output is correct |
13 | Correct | 61 ms | 7896 KB | Output is correct |
14 | Correct | 61 ms | 7776 KB | Output is correct |
15 | Correct | 59 ms | 7772 KB | Output is correct |
16 | Correct | 61 ms | 7864 KB | Output is correct |
17 | Correct | 60 ms | 7756 KB | Output is correct |
18 | Correct | 62 ms | 7908 KB | Output is correct |
19 | Correct | 60 ms | 7868 KB | Output is correct |
20 | Correct | 61 ms | 7876 KB | Output is correct |
21 | Correct | 74 ms | 7944 KB | Output is correct |
22 | Correct | 58 ms | 6884 KB | Output is correct |
23 | Correct | 59 ms | 7732 KB | Output is correct |
24 | Correct | 58 ms | 7628 KB | Output is correct |
25 | Correct | 64 ms | 7660 KB | Output is correct |
26 | Correct | 59 ms | 7744 KB | Output is correct |
27 | Correct | 58 ms | 7628 KB | Output is correct |
28 | Correct | 58 ms | 7748 KB | Output is correct |
29 | Correct | 65 ms | 7604 KB | Output is correct |
30 | Correct | 59 ms | 7756 KB | Output is correct |
31 | Correct | 60 ms | 7676 KB | Output is correct |
32 | Correct | 58 ms | 7664 KB | Output is correct |
33 | Correct | 63 ms | 7752 KB | Output is correct |
34 | Correct | 58 ms | 7724 KB | Output is correct |
35 | Correct | 59 ms | 7844 KB | Output is correct |
36 | Correct | 60 ms | 7788 KB | Output is correct |
37 | Correct | 57 ms | 7672 KB | Output is correct |
38 | Correct | 58 ms | 7676 KB | Output is correct |
39 | Correct | 60 ms | 7636 KB | Output is correct |
40 | Correct | 58 ms | 7620 KB | Output is correct |
41 | Correct | 58 ms | 7632 KB | Output is correct |
42 | Correct | 58 ms | 8196 KB | Output is correct |
43 | Runtime error | 19 ms | 9040 KB | Execution killed with signal 11 |
44 | Halted | 0 ms | 0 KB | - |