Submission #283460

# Submission time Handle Problem Language Result Execution time Memory
283460 2020-08-25T19:18:11 Z dolphingarlic Cubeword (CEOI19_cubeword) C++14
100 / 100
402 ms 18084 KB
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;

const ll MOD = 998244353;

inline int id(char c) {
	if (c >= 'a' && c <= 'z') return c - 'a';
	if (c >= 'A' && c <= 'Z') return c - 'A' + 26;
	return c - '0' + 52;
}

set<string> words[11];
ll cnt[62][62], dp[62][62][62], perm[8] = {24, 12, 12, 4, 12, 6, 4, 1};

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n;
	cin >> n;
	for (int i = 0; i < n; i++) {
		string s;
		cin >> s;
		words[s.size()].insert(s);
		reverse(s.begin(), s.end());
		words[s.size()].insert(s);
	}

	ll ans = 0;
	for (int l = 3; l < 11; l++) {
		memset(cnt, 0, sizeof cnt);
		memset(dp, 0, sizeof dp);
		for (string i : words[l]) cnt[id(i[0])][id(i.back())]++;
		for (int i = 0; i < 62; i++) {
			for (int a = 0; a < 62; a++) {
				for (int b = a; b < 62; b++) {
					for (int c = b; c < 62; c++) {
						dp[a][b][c] = (dp[a][b][c] + cnt[i][a] * cnt[i][b] % MOD * cnt[i][c] % MOD) % MOD;
					}
				}
			}
		}
		for (int a = 0; a < 62; a++) {
			for (int b = a; b < 62; b++) {
				for (int c = b; c < 62; c++) {
					for (int d = c; d < 62; d++) {
						int mask = (a == b) << 2 | (b == c) << 1 | (c == d);
						ans = (ans + dp[a][b][c] * dp[a][b][d] % MOD * dp[a][c][d] % MOD * dp[b][c][d] % MOD * perm[mask] % MOD) % MOD;
					}
				}
			}
		}
	}
	cout << ans;
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 346 ms 16888 KB Output is correct
2 Correct 341 ms 16888 KB Output is correct
3 Correct 351 ms 17088 KB Output is correct
4 Correct 346 ms 17020 KB Output is correct
5 Correct 367 ms 17144 KB Output is correct
6 Correct 330 ms 17016 KB Output is correct
7 Correct 329 ms 17144 KB Output is correct
8 Correct 328 ms 17016 KB Output is correct
9 Correct 342 ms 17016 KB Output is correct
10 Correct 402 ms 17020 KB Output is correct
11 Correct 343 ms 17144 KB Output is correct
12 Correct 336 ms 17144 KB Output is correct
13 Correct 328 ms 17016 KB Output is correct
14 Correct 340 ms 17016 KB Output is correct
15 Correct 329 ms 17016 KB Output is correct
16 Correct 329 ms 17044 KB Output is correct
17 Correct 335 ms 16920 KB Output is correct
18 Correct 334 ms 17100 KB Output is correct
19 Correct 324 ms 17016 KB Output is correct
20 Correct 337 ms 17016 KB Output is correct
21 Correct 325 ms 16888 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 346 ms 16888 KB Output is correct
2 Correct 341 ms 16888 KB Output is correct
3 Correct 351 ms 17088 KB Output is correct
4 Correct 346 ms 17020 KB Output is correct
5 Correct 367 ms 17144 KB Output is correct
6 Correct 330 ms 17016 KB Output is correct
7 Correct 329 ms 17144 KB Output is correct
8 Correct 328 ms 17016 KB Output is correct
9 Correct 342 ms 17016 KB Output is correct
10 Correct 402 ms 17020 KB Output is correct
11 Correct 343 ms 17144 KB Output is correct
12 Correct 336 ms 17144 KB Output is correct
13 Correct 328 ms 17016 KB Output is correct
14 Correct 340 ms 17016 KB Output is correct
15 Correct 329 ms 17016 KB Output is correct
16 Correct 329 ms 17044 KB Output is correct
17 Correct 335 ms 16920 KB Output is correct
18 Correct 334 ms 17100 KB Output is correct
19 Correct 324 ms 17016 KB Output is correct
20 Correct 337 ms 17016 KB Output is correct
21 Correct 325 ms 16888 KB Output is correct
22 Correct 330 ms 17784 KB Output is correct
23 Correct 340 ms 17656 KB Output is correct
24 Correct 329 ms 17804 KB Output is correct
25 Correct 340 ms 17656 KB Output is correct
26 Correct 346 ms 17656 KB Output is correct
27 Correct 342 ms 17656 KB Output is correct
28 Correct 333 ms 17732 KB Output is correct
29 Correct 328 ms 17680 KB Output is correct
30 Correct 338 ms 17656 KB Output is correct
31 Correct 355 ms 17656 KB Output is correct
32 Correct 341 ms 17656 KB Output is correct
33 Correct 326 ms 17660 KB Output is correct
34 Correct 322 ms 17656 KB Output is correct
35 Correct 327 ms 17660 KB Output is correct
36 Correct 325 ms 17656 KB Output is correct
37 Correct 337 ms 17656 KB Output is correct
38 Correct 324 ms 17656 KB Output is correct
39 Correct 326 ms 17704 KB Output is correct
40 Correct 318 ms 17656 KB Output is correct
41 Correct 332 ms 17708 KB Output is correct
42 Correct 321 ms 17528 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 346 ms 16888 KB Output is correct
2 Correct 341 ms 16888 KB Output is correct
3 Correct 351 ms 17088 KB Output is correct
4 Correct 346 ms 17020 KB Output is correct
5 Correct 367 ms 17144 KB Output is correct
6 Correct 330 ms 17016 KB Output is correct
7 Correct 329 ms 17144 KB Output is correct
8 Correct 328 ms 17016 KB Output is correct
9 Correct 342 ms 17016 KB Output is correct
10 Correct 402 ms 17020 KB Output is correct
11 Correct 343 ms 17144 KB Output is correct
12 Correct 336 ms 17144 KB Output is correct
13 Correct 328 ms 17016 KB Output is correct
14 Correct 340 ms 17016 KB Output is correct
15 Correct 329 ms 17016 KB Output is correct
16 Correct 329 ms 17044 KB Output is correct
17 Correct 335 ms 16920 KB Output is correct
18 Correct 334 ms 17100 KB Output is correct
19 Correct 324 ms 17016 KB Output is correct
20 Correct 337 ms 17016 KB Output is correct
21 Correct 325 ms 16888 KB Output is correct
22 Correct 330 ms 17784 KB Output is correct
23 Correct 340 ms 17656 KB Output is correct
24 Correct 329 ms 17804 KB Output is correct
25 Correct 340 ms 17656 KB Output is correct
26 Correct 346 ms 17656 KB Output is correct
27 Correct 342 ms 17656 KB Output is correct
28 Correct 333 ms 17732 KB Output is correct
29 Correct 328 ms 17680 KB Output is correct
30 Correct 338 ms 17656 KB Output is correct
31 Correct 355 ms 17656 KB Output is correct
32 Correct 341 ms 17656 KB Output is correct
33 Correct 326 ms 17660 KB Output is correct
34 Correct 322 ms 17656 KB Output is correct
35 Correct 327 ms 17660 KB Output is correct
36 Correct 325 ms 17656 KB Output is correct
37 Correct 337 ms 17656 KB Output is correct
38 Correct 324 ms 17656 KB Output is correct
39 Correct 326 ms 17704 KB Output is correct
40 Correct 318 ms 17656 KB Output is correct
41 Correct 332 ms 17708 KB Output is correct
42 Correct 321 ms 17528 KB Output is correct
43 Correct 336 ms 17528 KB Output is correct
44 Correct 327 ms 17660 KB Output is correct
45 Correct 328 ms 17656 KB Output is correct
46 Correct 323 ms 17528 KB Output is correct
47 Correct 347 ms 17656 KB Output is correct
48 Correct 338 ms 17528 KB Output is correct
49 Correct 341 ms 17636 KB Output is correct
50 Correct 347 ms 17656 KB Output is correct
51 Correct 358 ms 17528 KB Output is correct
52 Correct 354 ms 17660 KB Output is correct
53 Correct 336 ms 17656 KB Output is correct
54 Correct 337 ms 17784 KB Output is correct
55 Correct 330 ms 17528 KB Output is correct
56 Correct 335 ms 17656 KB Output is correct
57 Correct 342 ms 17656 KB Output is correct
58 Correct 342 ms 17656 KB Output is correct
59 Correct 337 ms 17636 KB Output is correct
60 Correct 329 ms 17656 KB Output is correct
61 Correct 327 ms 17632 KB Output is correct
62 Correct 362 ms 17528 KB Output is correct
63 Correct 322 ms 17528 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 346 ms 16888 KB Output is correct
2 Correct 341 ms 16888 KB Output is correct
3 Correct 351 ms 17088 KB Output is correct
4 Correct 346 ms 17020 KB Output is correct
5 Correct 367 ms 17144 KB Output is correct
6 Correct 330 ms 17016 KB Output is correct
7 Correct 329 ms 17144 KB Output is correct
8 Correct 328 ms 17016 KB Output is correct
9 Correct 342 ms 17016 KB Output is correct
10 Correct 402 ms 17020 KB Output is correct
11 Correct 343 ms 17144 KB Output is correct
12 Correct 336 ms 17144 KB Output is correct
13 Correct 328 ms 17016 KB Output is correct
14 Correct 340 ms 17016 KB Output is correct
15 Correct 329 ms 17016 KB Output is correct
16 Correct 329 ms 17044 KB Output is correct
17 Correct 335 ms 16920 KB Output is correct
18 Correct 334 ms 17100 KB Output is correct
19 Correct 324 ms 17016 KB Output is correct
20 Correct 337 ms 17016 KB Output is correct
21 Correct 325 ms 16888 KB Output is correct
22 Correct 330 ms 17784 KB Output is correct
23 Correct 340 ms 17656 KB Output is correct
24 Correct 329 ms 17804 KB Output is correct
25 Correct 340 ms 17656 KB Output is correct
26 Correct 346 ms 17656 KB Output is correct
27 Correct 342 ms 17656 KB Output is correct
28 Correct 333 ms 17732 KB Output is correct
29 Correct 328 ms 17680 KB Output is correct
30 Correct 338 ms 17656 KB Output is correct
31 Correct 355 ms 17656 KB Output is correct
32 Correct 341 ms 17656 KB Output is correct
33 Correct 326 ms 17660 KB Output is correct
34 Correct 322 ms 17656 KB Output is correct
35 Correct 327 ms 17660 KB Output is correct
36 Correct 325 ms 17656 KB Output is correct
37 Correct 337 ms 17656 KB Output is correct
38 Correct 324 ms 17656 KB Output is correct
39 Correct 326 ms 17704 KB Output is correct
40 Correct 318 ms 17656 KB Output is correct
41 Correct 332 ms 17708 KB Output is correct
42 Correct 321 ms 17528 KB Output is correct
43 Correct 336 ms 17528 KB Output is correct
44 Correct 327 ms 17660 KB Output is correct
45 Correct 328 ms 17656 KB Output is correct
46 Correct 323 ms 17528 KB Output is correct
47 Correct 347 ms 17656 KB Output is correct
48 Correct 338 ms 17528 KB Output is correct
49 Correct 341 ms 17636 KB Output is correct
50 Correct 347 ms 17656 KB Output is correct
51 Correct 358 ms 17528 KB Output is correct
52 Correct 354 ms 17660 KB Output is correct
53 Correct 336 ms 17656 KB Output is correct
54 Correct 337 ms 17784 KB Output is correct
55 Correct 330 ms 17528 KB Output is correct
56 Correct 335 ms 17656 KB Output is correct
57 Correct 342 ms 17656 KB Output is correct
58 Correct 342 ms 17656 KB Output is correct
59 Correct 337 ms 17636 KB Output is correct
60 Correct 329 ms 17656 KB Output is correct
61 Correct 327 ms 17632 KB Output is correct
62 Correct 362 ms 17528 KB Output is correct
63 Correct 322 ms 17528 KB Output is correct
64 Correct 331 ms 17920 KB Output is correct
65 Correct 327 ms 17784 KB Output is correct
66 Correct 327 ms 18084 KB Output is correct
67 Correct 323 ms 17872 KB Output is correct
68 Correct 327 ms 17784 KB Output is correct
69 Correct 329 ms 17872 KB Output is correct
70 Correct 332 ms 17912 KB Output is correct
71 Correct 328 ms 17912 KB Output is correct
72 Correct 326 ms 17784 KB Output is correct
73 Correct 334 ms 17784 KB Output is correct
74 Correct 383 ms 17784 KB Output is correct
75 Correct 380 ms 17952 KB Output is correct
76 Correct 338 ms 17784 KB Output is correct
77 Correct 346 ms 17780 KB Output is correct
78 Correct 335 ms 17852 KB Output is correct
79 Correct 340 ms 17784 KB Output is correct
80 Correct 325 ms 17912 KB Output is correct
81 Correct 333 ms 18040 KB Output is correct
82 Correct 329 ms 17912 KB Output is correct
83 Correct 332 ms 17912 KB Output is correct
84 Correct 326 ms 17784 KB Output is correct