# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
321234 | 2020-11-11T16:01:58 Z | phathnv | Cubeword (CEOI19_cubeword) | C++11 | 277 ms | 13272 KB |
#include <bits/stdc++.h> #define mp make_pair #define X first #define Y second #define taskname "Cubeword" using namespace std; typedef long long ll; typedef pair <int, int> ii; const int L = 8; const int M = 62; const int MOD = 998244353; int n, adj[L][M][M], cnt[L][M][M][M]; vector <string> words; int ind(char ch){ if ('a' <= ch && ch <= 'z') return ch - 'a'; if ('A' <= ch && ch <= 'Z') return ch - 'A' + 26; return ch - '0' + 52; } void readInput(){ ios_base::sync_with_stdio(0); cin.tie(0); cin >> n; for(int i = 1; i <= n; i++){ string s; cin >> s; words.push_back(s); reverse(s.begin(), s.end()); words.push_back(s); } sort(words.begin(), words.end()); words.resize(unique(words.begin(), words.end()) - words.begin()); for(string &s : words){ int fr = ind(s.front()); int bk = ind(s.back()); adj[s.size() - 3][fr][bk]++; } } void add(int &x, const int &y){ x += y; x -= (x >= MOD) * MOD; } int cntWays(int a, int b, int c, int d){ if (a == b && b == c && c == d) return 1; if ((a == b && b == c) || (b == c && c == d)) return 4; if (a == b && c == d) return 6; if (a == b || b == c || c == d) return 12; return 24; } void solve(){ int res = 0; for(int len = 0; len < L; len++) for(int r = 0; r < M; r++) for(int a = 0; a < M; a++) for(int b = a; b < M; b++) for(int c = b; c < M; c++){ add(cnt[len][a][b][c], (ll) adj[len][r][a] * adj[len][r][b] * adj[len][r][c] % MOD); } for(int len = 0; len < L; len++) for(int a = 0; a < M; a++) for(int b = a; b < M; b++) for(int c = b; c < M; c++) for(int d = c; d < M; d++){ int val = (ll) cnt[len][a][b][c] * cnt[len][a][b][d] % MOD * cnt[len][a][c][d] % MOD * cnt[len][b][c][d] % MOD; add(res, (ll) val * cntWays(a, b, c, d) % MOD); } cout << res; } int main(){ if (fopen(taskname".inp", "r")){ freopen(taskname".inp", "r", stdin); freopen(taskname".out", "w", stdout); } readInput(); solve(); return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 260 ms | 12228 KB | Output is correct |
2 | Correct | 264 ms | 13124 KB | Output is correct |
3 | Correct | 259 ms | 13060 KB | Output is correct |
4 | Correct | 259 ms | 13120 KB | Output is correct |
5 | Correct | 257 ms | 13124 KB | Output is correct |
6 | Correct | 258 ms | 13060 KB | Output is correct |
7 | Correct | 259 ms | 13120 KB | Output is correct |
8 | Correct | 261 ms | 13124 KB | Output is correct |
9 | Correct | 259 ms | 13124 KB | Output is correct |
10 | Correct | 260 ms | 13128 KB | Output is correct |
11 | Correct | 256 ms | 13128 KB | Output is correct |
12 | Correct | 262 ms | 13128 KB | Output is correct |
13 | Correct | 258 ms | 13124 KB | Output is correct |
14 | Correct | 261 ms | 13124 KB | Output is correct |
15 | Correct | 270 ms | 13120 KB | Output is correct |
16 | Correct | 256 ms | 13124 KB | Output is correct |
17 | Correct | 256 ms | 13124 KB | Output is correct |
18 | Correct | 269 ms | 13124 KB | Output is correct |
19 | Correct | 258 ms | 13124 KB | Output is correct |
20 | Correct | 265 ms | 13128 KB | Output is correct |
21 | Correct | 259 ms | 13140 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 260 ms | 12228 KB | Output is correct |
2 | Correct | 264 ms | 13124 KB | Output is correct |
3 | Correct | 259 ms | 13060 KB | Output is correct |
4 | Correct | 259 ms | 13120 KB | Output is correct |
5 | Correct | 257 ms | 13124 KB | Output is correct |
6 | Correct | 258 ms | 13060 KB | Output is correct |
7 | Correct | 259 ms | 13120 KB | Output is correct |
8 | Correct | 261 ms | 13124 KB | Output is correct |
9 | Correct | 259 ms | 13124 KB | Output is correct |
10 | Correct | 260 ms | 13128 KB | Output is correct |
11 | Correct | 256 ms | 13128 KB | Output is correct |
12 | Correct | 262 ms | 13128 KB | Output is correct |
13 | Correct | 258 ms | 13124 KB | Output is correct |
14 | Correct | 261 ms | 13124 KB | Output is correct |
15 | Correct | 270 ms | 13120 KB | Output is correct |
16 | Correct | 256 ms | 13124 KB | Output is correct |
17 | Correct | 256 ms | 13124 KB | Output is correct |
18 | Correct | 269 ms | 13124 KB | Output is correct |
19 | Correct | 258 ms | 13124 KB | Output is correct |
20 | Correct | 265 ms | 13128 KB | Output is correct |
21 | Correct | 259 ms | 13140 KB | Output is correct |
22 | Correct | 277 ms | 13124 KB | Output is correct |
23 | Correct | 262 ms | 13124 KB | Output is correct |
24 | Correct | 259 ms | 12996 KB | Output is correct |
25 | Correct | 269 ms | 13028 KB | Output is correct |
26 | Correct | 259 ms | 13124 KB | Output is correct |
27 | Correct | 265 ms | 12996 KB | Output is correct |
28 | Correct | 258 ms | 13124 KB | Output is correct |
29 | Correct | 255 ms | 12996 KB | Output is correct |
30 | Correct | 263 ms | 13124 KB | Output is correct |
31 | Correct | 258 ms | 12996 KB | Output is correct |
32 | Correct | 256 ms | 12996 KB | Output is correct |
33 | Correct | 262 ms | 12996 KB | Output is correct |
34 | Correct | 254 ms | 12996 KB | Output is correct |
35 | Correct | 261 ms | 13128 KB | Output is correct |
36 | Correct | 259 ms | 13128 KB | Output is correct |
37 | Correct | 257 ms | 12996 KB | Output is correct |
38 | Correct | 258 ms | 12996 KB | Output is correct |
39 | Correct | 258 ms | 12996 KB | Output is correct |
40 | Correct | 261 ms | 13124 KB | Output is correct |
41 | Correct | 255 ms | 13000 KB | Output is correct |
42 | Correct | 256 ms | 12996 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 260 ms | 12228 KB | Output is correct |
2 | Correct | 264 ms | 13124 KB | Output is correct |
3 | Correct | 259 ms | 13060 KB | Output is correct |
4 | Correct | 259 ms | 13120 KB | Output is correct |
5 | Correct | 257 ms | 13124 KB | Output is correct |
6 | Correct | 258 ms | 13060 KB | Output is correct |
7 | Correct | 259 ms | 13120 KB | Output is correct |
8 | Correct | 261 ms | 13124 KB | Output is correct |
9 | Correct | 259 ms | 13124 KB | Output is correct |
10 | Correct | 260 ms | 13128 KB | Output is correct |
11 | Correct | 256 ms | 13128 KB | Output is correct |
12 | Correct | 262 ms | 13128 KB | Output is correct |
13 | Correct | 258 ms | 13124 KB | Output is correct |
14 | Correct | 261 ms | 13124 KB | Output is correct |
15 | Correct | 270 ms | 13120 KB | Output is correct |
16 | Correct | 256 ms | 13124 KB | Output is correct |
17 | Correct | 256 ms | 13124 KB | Output is correct |
18 | Correct | 269 ms | 13124 KB | Output is correct |
19 | Correct | 258 ms | 13124 KB | Output is correct |
20 | Correct | 265 ms | 13128 KB | Output is correct |
21 | Correct | 259 ms | 13140 KB | Output is correct |
22 | Correct | 277 ms | 13124 KB | Output is correct |
23 | Correct | 262 ms | 13124 KB | Output is correct |
24 | Correct | 259 ms | 12996 KB | Output is correct |
25 | Correct | 269 ms | 13028 KB | Output is correct |
26 | Correct | 259 ms | 13124 KB | Output is correct |
27 | Correct | 265 ms | 12996 KB | Output is correct |
28 | Correct | 258 ms | 13124 KB | Output is correct |
29 | Correct | 255 ms | 12996 KB | Output is correct |
30 | Correct | 263 ms | 13124 KB | Output is correct |
31 | Correct | 258 ms | 12996 KB | Output is correct |
32 | Correct | 256 ms | 12996 KB | Output is correct |
33 | Correct | 262 ms | 12996 KB | Output is correct |
34 | Correct | 254 ms | 12996 KB | Output is correct |
35 | Correct | 261 ms | 13128 KB | Output is correct |
36 | Correct | 259 ms | 13128 KB | Output is correct |
37 | Correct | 257 ms | 12996 KB | Output is correct |
38 | Correct | 258 ms | 12996 KB | Output is correct |
39 | Correct | 258 ms | 12996 KB | Output is correct |
40 | Correct | 261 ms | 13124 KB | Output is correct |
41 | Correct | 255 ms | 13000 KB | Output is correct |
42 | Correct | 256 ms | 12996 KB | Output is correct |
43 | Correct | 259 ms | 13124 KB | Output is correct |
44 | Correct | 258 ms | 13124 KB | Output is correct |
45 | Correct | 260 ms | 13080 KB | Output is correct |
46 | Correct | 258 ms | 13124 KB | Output is correct |
47 | Correct | 261 ms | 13124 KB | Output is correct |
48 | Correct | 260 ms | 13220 KB | Output is correct |
49 | Correct | 254 ms | 13124 KB | Output is correct |
50 | Correct | 257 ms | 13124 KB | Output is correct |
51 | Correct | 257 ms | 13272 KB | Output is correct |
52 | Correct | 256 ms | 13124 KB | Output is correct |
53 | Correct | 264 ms | 13128 KB | Output is correct |
54 | Correct | 262 ms | 13124 KB | Output is correct |
55 | Correct | 263 ms | 13124 KB | Output is correct |
56 | Correct | 260 ms | 13256 KB | Output is correct |
57 | Correct | 269 ms | 13124 KB | Output is correct |
58 | Correct | 260 ms | 13128 KB | Output is correct |
59 | Correct | 258 ms | 13124 KB | Output is correct |
60 | Correct | 260 ms | 13124 KB | Output is correct |
61 | Correct | 256 ms | 13124 KB | Output is correct |
62 | Correct | 253 ms | 13124 KB | Output is correct |
63 | Correct | 258 ms | 13000 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 260 ms | 12228 KB | Output is correct |
2 | Correct | 264 ms | 13124 KB | Output is correct |
3 | Correct | 259 ms | 13060 KB | Output is correct |
4 | Correct | 259 ms | 13120 KB | Output is correct |
5 | Correct | 257 ms | 13124 KB | Output is correct |
6 | Correct | 258 ms | 13060 KB | Output is correct |
7 | Correct | 259 ms | 13120 KB | Output is correct |
8 | Correct | 261 ms | 13124 KB | Output is correct |
9 | Correct | 259 ms | 13124 KB | Output is correct |
10 | Correct | 260 ms | 13128 KB | Output is correct |
11 | Correct | 256 ms | 13128 KB | Output is correct |
12 | Correct | 262 ms | 13128 KB | Output is correct |
13 | Correct | 258 ms | 13124 KB | Output is correct |
14 | Correct | 261 ms | 13124 KB | Output is correct |
15 | Correct | 270 ms | 13120 KB | Output is correct |
16 | Correct | 256 ms | 13124 KB | Output is correct |
17 | Correct | 256 ms | 13124 KB | Output is correct |
18 | Correct | 269 ms | 13124 KB | Output is correct |
19 | Correct | 258 ms | 13124 KB | Output is correct |
20 | Correct | 265 ms | 13128 KB | Output is correct |
21 | Correct | 259 ms | 13140 KB | Output is correct |
22 | Correct | 277 ms | 13124 KB | Output is correct |
23 | Correct | 262 ms | 13124 KB | Output is correct |
24 | Correct | 259 ms | 12996 KB | Output is correct |
25 | Correct | 269 ms | 13028 KB | Output is correct |
26 | Correct | 259 ms | 13124 KB | Output is correct |
27 | Correct | 265 ms | 12996 KB | Output is correct |
28 | Correct | 258 ms | 13124 KB | Output is correct |
29 | Correct | 255 ms | 12996 KB | Output is correct |
30 | Correct | 263 ms | 13124 KB | Output is correct |
31 | Correct | 258 ms | 12996 KB | Output is correct |
32 | Correct | 256 ms | 12996 KB | Output is correct |
33 | Correct | 262 ms | 12996 KB | Output is correct |
34 | Correct | 254 ms | 12996 KB | Output is correct |
35 | Correct | 261 ms | 13128 KB | Output is correct |
36 | Correct | 259 ms | 13128 KB | Output is correct |
37 | Correct | 257 ms | 12996 KB | Output is correct |
38 | Correct | 258 ms | 12996 KB | Output is correct |
39 | Correct | 258 ms | 12996 KB | Output is correct |
40 | Correct | 261 ms | 13124 KB | Output is correct |
41 | Correct | 255 ms | 13000 KB | Output is correct |
42 | Correct | 256 ms | 12996 KB | Output is correct |
43 | Correct | 259 ms | 13124 KB | Output is correct |
44 | Correct | 258 ms | 13124 KB | Output is correct |
45 | Correct | 260 ms | 13080 KB | Output is correct |
46 | Correct | 258 ms | 13124 KB | Output is correct |
47 | Correct | 261 ms | 13124 KB | Output is correct |
48 | Correct | 260 ms | 13220 KB | Output is correct |
49 | Correct | 254 ms | 13124 KB | Output is correct |
50 | Correct | 257 ms | 13124 KB | Output is correct |
51 | Correct | 257 ms | 13272 KB | Output is correct |
52 | Correct | 256 ms | 13124 KB | Output is correct |
53 | Correct | 264 ms | 13128 KB | Output is correct |
54 | Correct | 262 ms | 13124 KB | Output is correct |
55 | Correct | 263 ms | 13124 KB | Output is correct |
56 | Correct | 260 ms | 13256 KB | Output is correct |
57 | Correct | 269 ms | 13124 KB | Output is correct |
58 | Correct | 260 ms | 13128 KB | Output is correct |
59 | Correct | 258 ms | 13124 KB | Output is correct |
60 | Correct | 260 ms | 13124 KB | Output is correct |
61 | Correct | 256 ms | 13124 KB | Output is correct |
62 | Correct | 253 ms | 13124 KB | Output is correct |
63 | Correct | 258 ms | 13000 KB | Output is correct |
64 | Correct | 255 ms | 13124 KB | Output is correct |
65 | Correct | 258 ms | 13128 KB | Output is correct |
66 | Correct | 257 ms | 13132 KB | Output is correct |
67 | Correct | 256 ms | 13064 KB | Output is correct |
68 | Correct | 255 ms | 13124 KB | Output is correct |
69 | Correct | 253 ms | 13128 KB | Output is correct |
70 | Correct | 256 ms | 13124 KB | Output is correct |
71 | Correct | 254 ms | 13124 KB | Output is correct |
72 | Correct | 254 ms | 13120 KB | Output is correct |
73 | Correct | 252 ms | 13128 KB | Output is correct |
74 | Correct | 257 ms | 13272 KB | Output is correct |
75 | Correct | 254 ms | 13124 KB | Output is correct |
76 | Correct | 258 ms | 13148 KB | Output is correct |
77 | Correct | 253 ms | 13124 KB | Output is correct |
78 | Correct | 259 ms | 13124 KB | Output is correct |
79 | Correct | 257 ms | 13124 KB | Output is correct |
80 | Correct | 254 ms | 13092 KB | Output is correct |
81 | Correct | 254 ms | 13124 KB | Output is correct |
82 | Correct | 260 ms | 13180 KB | Output is correct |
83 | Correct | 261 ms | 13252 KB | Output is correct |
84 | Correct | 255 ms | 13124 KB | Output is correct |