# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
660107 | 2022-11-20T11:12:18 Z | 600Mihnea | Cubeword (CEOI19_cubeword) | C++17 | 362 ms | 9232 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; 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 = a; b < ALPHABET_SIZE; b++) { for (size_t c = b; 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; } cnt3[a][c][b] = cnt3[b][a][c] = cnt3[b][c][a] = cnt3[c][a][b] = cnt3[c][b][a] = cnt3[a][b][c]; } } } for (size_t a = 0; a < ALPHABET_SIZE; a++) { for (size_t b = 0; b < a; b++) { for (size_t c = 0; c < b; c++) { for (size_t d = 0; d < c; 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 + 24LL * x1 % MODULO * x2 % MODULO * x3 % MODULO * x4) % 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++) { if (a == b || a == c || b == 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; } } else { for (size_t d : {a, b, c}) { 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; } } } } } } cout << solution << "\n"; return 0; }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 234 ms | 8820 KB | Output is correct |
2 | Correct | 237 ms | 8856 KB | Output is correct |
3 | Correct | 357 ms | 8876 KB | Output is correct |
4 | Correct | 241 ms | 8808 KB | Output is correct |
5 | Correct | 245 ms | 8804 KB | Output is correct |
6 | Correct | 235 ms | 8904 KB | Output is correct |
7 | Correct | 242 ms | 8764 KB | Output is correct |
8 | Correct | 250 ms | 8820 KB | Output is correct |
9 | Correct | 242 ms | 9004 KB | Output is correct |
10 | Correct | 235 ms | 8728 KB | Output is correct |
11 | Correct | 242 ms | 8776 KB | Output is correct |
12 | Correct | 304 ms | 8780 KB | Output is correct |
13 | Correct | 255 ms | 8780 KB | Output is correct |
14 | Correct | 362 ms | 8708 KB | Output is correct |
15 | Correct | 243 ms | 8760 KB | Output is correct |
16 | Correct | 252 ms | 8800 KB | Output is correct |
17 | Correct | 236 ms | 8716 KB | Output is correct |
18 | Correct | 235 ms | 8792 KB | Output is correct |
19 | Correct | 241 ms | 8892 KB | Output is correct |
20 | Correct | 260 ms | 8732 KB | Output is correct |
21 | Correct | 246 ms | 8836 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 234 ms | 8820 KB | Output is correct |
2 | Correct | 237 ms | 8856 KB | Output is correct |
3 | Correct | 357 ms | 8876 KB | Output is correct |
4 | Correct | 241 ms | 8808 KB | Output is correct |
5 | Correct | 245 ms | 8804 KB | Output is correct |
6 | Correct | 235 ms | 8904 KB | Output is correct |
7 | Correct | 242 ms | 8764 KB | Output is correct |
8 | Correct | 250 ms | 8820 KB | Output is correct |
9 | Correct | 242 ms | 9004 KB | Output is correct |
10 | Correct | 235 ms | 8728 KB | Output is correct |
11 | Correct | 242 ms | 8776 KB | Output is correct |
12 | Correct | 304 ms | 8780 KB | Output is correct |
13 | Correct | 255 ms | 8780 KB | Output is correct |
14 | Correct | 362 ms | 8708 KB | Output is correct |
15 | Correct | 243 ms | 8760 KB | Output is correct |
16 | Correct | 252 ms | 8800 KB | Output is correct |
17 | Correct | 236 ms | 8716 KB | Output is correct |
18 | Correct | 235 ms | 8792 KB | Output is correct |
19 | Correct | 241 ms | 8892 KB | Output is correct |
20 | Correct | 260 ms | 8732 KB | Output is correct |
21 | Correct | 246 ms | 8836 KB | Output is correct |
22 | Correct | 352 ms | 7848 KB | Output is correct |
23 | Correct | 244 ms | 7936 KB | Output is correct |
24 | Correct | 241 ms | 7848 KB | Output is correct |
25 | Correct | 232 ms | 7724 KB | Output is correct |
26 | Correct | 236 ms | 7908 KB | Output is correct |
27 | Correct | 235 ms | 7760 KB | Output is correct |
28 | Correct | 239 ms | 7932 KB | Output is correct |
29 | Correct | 240 ms | 7748 KB | Output is correct |
30 | Correct | 240 ms | 7892 KB | Output is correct |
31 | Correct | 238 ms | 7804 KB | Output is correct |
32 | Correct | 228 ms | 7792 KB | Output is correct |
33 | Correct | 243 ms | 7908 KB | Output is correct |
34 | Correct | 240 ms | 7840 KB | Output is correct |
35 | Correct | 233 ms | 7984 KB | Output is correct |
36 | Correct | 235 ms | 7872 KB | Output is correct |
37 | Correct | 238 ms | 7744 KB | Output is correct |
38 | Correct | 250 ms | 7824 KB | Output is correct |
39 | Correct | 301 ms | 7840 KB | Output is correct |
40 | Correct | 235 ms | 7752 KB | Output is correct |
41 | Correct | 238 ms | 7764 KB | Output is correct |
42 | Correct | 236 ms | 8372 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 234 ms | 8820 KB | Output is correct |
2 | Correct | 237 ms | 8856 KB | Output is correct |
3 | Correct | 357 ms | 8876 KB | Output is correct |
4 | Correct | 241 ms | 8808 KB | Output is correct |
5 | Correct | 245 ms | 8804 KB | Output is correct |
6 | Correct | 235 ms | 8904 KB | Output is correct |
7 | Correct | 242 ms | 8764 KB | Output is correct |
8 | Correct | 250 ms | 8820 KB | Output is correct |
9 | Correct | 242 ms | 9004 KB | Output is correct |
10 | Correct | 235 ms | 8728 KB | Output is correct |
11 | Correct | 242 ms | 8776 KB | Output is correct |
12 | Correct | 304 ms | 8780 KB | Output is correct |
13 | Correct | 255 ms | 8780 KB | Output is correct |
14 | Correct | 362 ms | 8708 KB | Output is correct |
15 | Correct | 243 ms | 8760 KB | Output is correct |
16 | Correct | 252 ms | 8800 KB | Output is correct |
17 | Correct | 236 ms | 8716 KB | Output is correct |
18 | Correct | 235 ms | 8792 KB | Output is correct |
19 | Correct | 241 ms | 8892 KB | Output is correct |
20 | Correct | 260 ms | 8732 KB | Output is correct |
21 | Correct | 246 ms | 8836 KB | Output is correct |
22 | Correct | 352 ms | 7848 KB | Output is correct |
23 | Correct | 244 ms | 7936 KB | Output is correct |
24 | Correct | 241 ms | 7848 KB | Output is correct |
25 | Correct | 232 ms | 7724 KB | Output is correct |
26 | Correct | 236 ms | 7908 KB | Output is correct |
27 | Correct | 235 ms | 7760 KB | Output is correct |
28 | Correct | 239 ms | 7932 KB | Output is correct |
29 | Correct | 240 ms | 7748 KB | Output is correct |
30 | Correct | 240 ms | 7892 KB | Output is correct |
31 | Correct | 238 ms | 7804 KB | Output is correct |
32 | Correct | 228 ms | 7792 KB | Output is correct |
33 | Correct | 243 ms | 7908 KB | Output is correct |
34 | Correct | 240 ms | 7840 KB | Output is correct |
35 | Correct | 233 ms | 7984 KB | Output is correct |
36 | Correct | 235 ms | 7872 KB | Output is correct |
37 | Correct | 238 ms | 7744 KB | Output is correct |
38 | Correct | 250 ms | 7824 KB | Output is correct |
39 | Correct | 301 ms | 7840 KB | Output is correct |
40 | Correct | 235 ms | 7752 KB | Output is correct |
41 | Correct | 238 ms | 7764 KB | Output is correct |
42 | Correct | 236 ms | 8372 KB | Output is correct |
43 | Correct | 237 ms | 8484 KB | Output is correct |
44 | Correct | 243 ms | 9044 KB | Output is correct |
45 | Correct | 241 ms | 8828 KB | Output is correct |
46 | Correct | 273 ms | 9232 KB | Output is correct |
47 | Correct | 243 ms | 8556 KB | Output is correct |
48 | Correct | 262 ms | 8792 KB | Output is correct |
49 | Correct | 257 ms | 8872 KB | Output is correct |
50 | Correct | 258 ms | 8816 KB | Output is correct |
51 | Correct | 242 ms | 8800 KB | Output is correct |
52 | Correct | 245 ms | 9032 KB | Output is correct |
53 | Correct | 272 ms | 8632 KB | Output is correct |
54 | Correct | 253 ms | 8928 KB | Output is correct |
55 | Correct | 267 ms | 8804 KB | Output is correct |
56 | Correct | 245 ms | 9028 KB | Output is correct |
57 | Correct | 232 ms | 8568 KB | Output is correct |
58 | Correct | 230 ms | 8800 KB | Output is correct |
59 | Correct | 226 ms | 8552 KB | Output is correct |
60 | Correct | 229 ms | 8652 KB | Output is correct |
61 | Correct | 234 ms | 8544 KB | Output is correct |
62 | Correct | 228 ms | 8828 KB | Output is correct |
63 | Correct | 230 ms | 8560 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 234 ms | 8820 KB | Output is correct |
2 | Correct | 237 ms | 8856 KB | Output is correct |
3 | Correct | 357 ms | 8876 KB | Output is correct |
4 | Correct | 241 ms | 8808 KB | Output is correct |
5 | Correct | 245 ms | 8804 KB | Output is correct |
6 | Correct | 235 ms | 8904 KB | Output is correct |
7 | Correct | 242 ms | 8764 KB | Output is correct |
8 | Correct | 250 ms | 8820 KB | Output is correct |
9 | Correct | 242 ms | 9004 KB | Output is correct |
10 | Correct | 235 ms | 8728 KB | Output is correct |
11 | Correct | 242 ms | 8776 KB | Output is correct |
12 | Correct | 304 ms | 8780 KB | Output is correct |
13 | Correct | 255 ms | 8780 KB | Output is correct |
14 | Correct | 362 ms | 8708 KB | Output is correct |
15 | Correct | 243 ms | 8760 KB | Output is correct |
16 | Correct | 252 ms | 8800 KB | Output is correct |
17 | Correct | 236 ms | 8716 KB | Output is correct |
18 | Correct | 235 ms | 8792 KB | Output is correct |
19 | Correct | 241 ms | 8892 KB | Output is correct |
20 | Correct | 260 ms | 8732 KB | Output is correct |
21 | Correct | 246 ms | 8836 KB | Output is correct |
22 | Correct | 352 ms | 7848 KB | Output is correct |
23 | Correct | 244 ms | 7936 KB | Output is correct |
24 | Correct | 241 ms | 7848 KB | Output is correct |
25 | Correct | 232 ms | 7724 KB | Output is correct |
26 | Correct | 236 ms | 7908 KB | Output is correct |
27 | Correct | 235 ms | 7760 KB | Output is correct |
28 | Correct | 239 ms | 7932 KB | Output is correct |
29 | Correct | 240 ms | 7748 KB | Output is correct |
30 | Correct | 240 ms | 7892 KB | Output is correct |
31 | Correct | 238 ms | 7804 KB | Output is correct |
32 | Correct | 228 ms | 7792 KB | Output is correct |
33 | Correct | 243 ms | 7908 KB | Output is correct |
34 | Correct | 240 ms | 7840 KB | Output is correct |
35 | Correct | 233 ms | 7984 KB | Output is correct |
36 | Correct | 235 ms | 7872 KB | Output is correct |
37 | Correct | 238 ms | 7744 KB | Output is correct |
38 | Correct | 250 ms | 7824 KB | Output is correct |
39 | Correct | 301 ms | 7840 KB | Output is correct |
40 | Correct | 235 ms | 7752 KB | Output is correct |
41 | Correct | 238 ms | 7764 KB | Output is correct |
42 | Correct | 236 ms | 8372 KB | Output is correct |
43 | Correct | 237 ms | 8484 KB | Output is correct |
44 | Correct | 243 ms | 9044 KB | Output is correct |
45 | Correct | 241 ms | 8828 KB | Output is correct |
46 | Correct | 273 ms | 9232 KB | Output is correct |
47 | Correct | 243 ms | 8556 KB | Output is correct |
48 | Correct | 262 ms | 8792 KB | Output is correct |
49 | Correct | 257 ms | 8872 KB | Output is correct |
50 | Correct | 258 ms | 8816 KB | Output is correct |
51 | Correct | 242 ms | 8800 KB | Output is correct |
52 | Correct | 245 ms | 9032 KB | Output is correct |
53 | Correct | 272 ms | 8632 KB | Output is correct |
54 | Correct | 253 ms | 8928 KB | Output is correct |
55 | Correct | 267 ms | 8804 KB | Output is correct |
56 | Correct | 245 ms | 9028 KB | Output is correct |
57 | Correct | 232 ms | 8568 KB | Output is correct |
58 | Correct | 230 ms | 8800 KB | Output is correct |
59 | Correct | 226 ms | 8552 KB | Output is correct |
60 | Correct | 229 ms | 8652 KB | Output is correct |
61 | Correct | 234 ms | 8544 KB | Output is correct |
62 | Correct | 228 ms | 8828 KB | Output is correct |
63 | Correct | 230 ms | 8560 KB | Output is correct |
64 | Correct | 229 ms | 8916 KB | Output is correct |
65 | Correct | 229 ms | 8616 KB | Output is correct |
66 | Correct | 229 ms | 8648 KB | Output is correct |
67 | Correct | 238 ms | 8996 KB | Output is correct |
68 | Correct | 227 ms | 9056 KB | Output is correct |
69 | Correct | 233 ms | 9028 KB | Output is correct |
70 | Correct | 234 ms | 8928 KB | Output is correct |
71 | Correct | 227 ms | 9100 KB | Output is correct |
72 | Correct | 229 ms | 8788 KB | Output is correct |
73 | Correct | 230 ms | 8972 KB | Output is correct |
74 | Correct | 228 ms | 8540 KB | Output is correct |
75 | Correct | 230 ms | 8716 KB | Output is correct |
76 | Correct | 231 ms | 8644 KB | Output is correct |
77 | Correct | 227 ms | 8600 KB | Output is correct |
78 | Correct | 234 ms | 8844 KB | Output is correct |
79 | Correct | 230 ms | 9000 KB | Output is correct |
80 | Correct | 232 ms | 8940 KB | Output is correct |
81 | Correct | 226 ms | 8996 KB | Output is correct |
82 | Correct | 227 ms | 8560 KB | Output is correct |
83 | Correct | 226 ms | 8640 KB | Output is correct |
84 | Correct | 230 ms | 8812 KB | Output is correct |