Submission #821889

# Submission time Handle Problem Language Result Execution time Memory
821889 2023-08-11T19:57:34 Z NK_ Cubeword (CEOI19_cubeword) C++17
100 / 100
365 ms 8712 KB
#include <bits/stdc++.h>

using namespace std;

#define nl '\n'

const int MOD = 998244353;
using ll = int;
using str = string;

template<class T> using V = vector<T>;

int main() {
	cin.tie(0)->sync_with_stdio(0);
	
	int N; cin >> N;

	V<V<str>> A(11);
	for(int i = 0; i < N; i++) {
		str s; cin >> s;
		A[size(s)].push_back(s);
		reverse(begin(s), end(s));
		A[size(s)].push_back(s);
	}

	auto TO = [&](const char &c) {
		if (islower(c)) return c - 'a';
		if (isupper(c)) return c - 'A' + 26;
		if (isdigit(c)) return c - '0' + 52;
		return -1;
	};

	const int C = 62;

	V<ll> fact = {1, 1, 2, 6, 24};

	ll ans = 0;
	for(int l = 3; l <= 10; l++) {

		sort(begin(A[l]), end(A[l]));
		A[l].erase(unique(begin(A[l]), end(A[l])), end(A[l]));

		V<V<ll>> CNT(C, V<ll>(C));

		for(auto s : A[l]) CNT[TO(s.front())][TO(s.back())]++;

		V<V<V<ll>>> ways(C, V<V<ll>>(C, V<ll>(C)));

		for(int a = 0; a < C; a++) for(int b = 0; b < C; b++) if (CNT[a][b] != 0) {
			for(int c = b; c < C; c++) if (CNT[a][c] != 0) {
				for(int d = c; d < C; d++) if (CNT[a][d] != 0) {
					ll way = (((CNT[a][b] * 1LL * CNT[a][c]) % MOD) * 1LL * CNT[a][d]) % MOD;
					
					ways[b][c][d] += way; 
					if (ways[b][c][d] >= MOD) ways[b][c][d] -= MOD;
				}
			}
		}

		vector<int> v;
		vector<int> amt(C);

		for(int a = 0; a < C; a++) for(int b = a; b < C; b++) for(int c = b; c < C; c++) {
			if (ways[a][b][c] == 0) continue;
			for(int d = c; d < C; d++) if (min(ways[a][b][d], min(ways[a][c][d], ways[b][c][d])) != 0) {
				ll way = ((ways[a][b][c] * 1LL * ways[a][b][d]) % MOD) * 1LL * ((ways[a][c][d] * 1LL * ways[b][c][d]) % MOD) % MOD;

				

				ll res = fact[4];
				v = {a, b, c, d}; 
				for(const auto &x : v) amt[x]++;
				for(const auto &x : v) {
					res /= fact[amt[x]];
					amt[x] = 0;
				}

				ans += (way * 1LL * res) % MOD;
				if (ans >= MOD) ans -= MOD;
			}
		}

	}

	cout << ans << nl;

    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 46 ms 8552 KB Output is correct
2 Correct 46 ms 8560 KB Output is correct
3 Correct 51 ms 8584 KB Output is correct
4 Correct 46 ms 8592 KB Output is correct
5 Correct 46 ms 8712 KB Output is correct
6 Correct 45 ms 8608 KB Output is correct
7 Correct 45 ms 8612 KB Output is correct
8 Correct 45 ms 8568 KB Output is correct
9 Correct 46 ms 8528 KB Output is correct
10 Correct 45 ms 8616 KB Output is correct
11 Correct 46 ms 8580 KB Output is correct
12 Correct 53 ms 8612 KB Output is correct
13 Correct 46 ms 8600 KB Output is correct
14 Correct 46 ms 8612 KB Output is correct
15 Correct 46 ms 8612 KB Output is correct
16 Correct 46 ms 8568 KB Output is correct
17 Correct 45 ms 8608 KB Output is correct
18 Correct 46 ms 8520 KB Output is correct
19 Correct 45 ms 8552 KB Output is correct
20 Correct 45 ms 8616 KB Output is correct
21 Correct 49 ms 8544 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 46 ms 8552 KB Output is correct
2 Correct 46 ms 8560 KB Output is correct
3 Correct 51 ms 8584 KB Output is correct
4 Correct 46 ms 8592 KB Output is correct
5 Correct 46 ms 8712 KB Output is correct
6 Correct 45 ms 8608 KB Output is correct
7 Correct 45 ms 8612 KB Output is correct
8 Correct 45 ms 8568 KB Output is correct
9 Correct 46 ms 8528 KB Output is correct
10 Correct 45 ms 8616 KB Output is correct
11 Correct 46 ms 8580 KB Output is correct
12 Correct 53 ms 8612 KB Output is correct
13 Correct 46 ms 8600 KB Output is correct
14 Correct 46 ms 8612 KB Output is correct
15 Correct 46 ms 8612 KB Output is correct
16 Correct 46 ms 8568 KB Output is correct
17 Correct 45 ms 8608 KB Output is correct
18 Correct 46 ms 8520 KB Output is correct
19 Correct 45 ms 8552 KB Output is correct
20 Correct 45 ms 8616 KB Output is correct
21 Correct 49 ms 8544 KB Output is correct
22 Correct 48 ms 8472 KB Output is correct
23 Correct 56 ms 8476 KB Output is correct
24 Correct 48 ms 8480 KB Output is correct
25 Correct 48 ms 8456 KB Output is correct
26 Correct 50 ms 8376 KB Output is correct
27 Correct 48 ms 8480 KB Output is correct
28 Correct 49 ms 8452 KB Output is correct
29 Correct 48 ms 8472 KB Output is correct
30 Correct 48 ms 8464 KB Output is correct
31 Correct 58 ms 8436 KB Output is correct
32 Correct 49 ms 8480 KB Output is correct
33 Correct 47 ms 8460 KB Output is correct
34 Correct 47 ms 8476 KB Output is correct
35 Correct 47 ms 8508 KB Output is correct
36 Correct 47 ms 8496 KB Output is correct
37 Correct 48 ms 8420 KB Output is correct
38 Correct 47 ms 8472 KB Output is correct
39 Correct 48 ms 8492 KB Output is correct
40 Correct 49 ms 8480 KB Output is correct
41 Correct 48 ms 8460 KB Output is correct
42 Correct 47 ms 8484 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 46 ms 8552 KB Output is correct
2 Correct 46 ms 8560 KB Output is correct
3 Correct 51 ms 8584 KB Output is correct
4 Correct 46 ms 8592 KB Output is correct
5 Correct 46 ms 8712 KB Output is correct
6 Correct 45 ms 8608 KB Output is correct
7 Correct 45 ms 8612 KB Output is correct
8 Correct 45 ms 8568 KB Output is correct
9 Correct 46 ms 8528 KB Output is correct
10 Correct 45 ms 8616 KB Output is correct
11 Correct 46 ms 8580 KB Output is correct
12 Correct 53 ms 8612 KB Output is correct
13 Correct 46 ms 8600 KB Output is correct
14 Correct 46 ms 8612 KB Output is correct
15 Correct 46 ms 8612 KB Output is correct
16 Correct 46 ms 8568 KB Output is correct
17 Correct 45 ms 8608 KB Output is correct
18 Correct 46 ms 8520 KB Output is correct
19 Correct 45 ms 8552 KB Output is correct
20 Correct 45 ms 8616 KB Output is correct
21 Correct 49 ms 8544 KB Output is correct
22 Correct 48 ms 8472 KB Output is correct
23 Correct 56 ms 8476 KB Output is correct
24 Correct 48 ms 8480 KB Output is correct
25 Correct 48 ms 8456 KB Output is correct
26 Correct 50 ms 8376 KB Output is correct
27 Correct 48 ms 8480 KB Output is correct
28 Correct 49 ms 8452 KB Output is correct
29 Correct 48 ms 8472 KB Output is correct
30 Correct 48 ms 8464 KB Output is correct
31 Correct 58 ms 8436 KB Output is correct
32 Correct 49 ms 8480 KB Output is correct
33 Correct 47 ms 8460 KB Output is correct
34 Correct 47 ms 8476 KB Output is correct
35 Correct 47 ms 8508 KB Output is correct
36 Correct 47 ms 8496 KB Output is correct
37 Correct 48 ms 8420 KB Output is correct
38 Correct 47 ms 8472 KB Output is correct
39 Correct 48 ms 8492 KB Output is correct
40 Correct 49 ms 8480 KB Output is correct
41 Correct 48 ms 8460 KB Output is correct
42 Correct 47 ms 8484 KB Output is correct
43 Correct 74 ms 8432 KB Output is correct
44 Correct 74 ms 8472 KB Output is correct
45 Correct 76 ms 8464 KB Output is correct
46 Correct 73 ms 8452 KB Output is correct
47 Correct 80 ms 8444 KB Output is correct
48 Correct 75 ms 8440 KB Output is correct
49 Correct 73 ms 8432 KB Output is correct
50 Correct 76 ms 8492 KB Output is correct
51 Correct 74 ms 8428 KB Output is correct
52 Correct 80 ms 8452 KB Output is correct
53 Correct 76 ms 8452 KB Output is correct
54 Correct 77 ms 8436 KB Output is correct
55 Correct 74 ms 8440 KB Output is correct
56 Correct 74 ms 8452 KB Output is correct
57 Correct 73 ms 8428 KB Output is correct
58 Correct 79 ms 8452 KB Output is correct
59 Correct 76 ms 8444 KB Output is correct
60 Correct 80 ms 8452 KB Output is correct
61 Correct 74 ms 8420 KB Output is correct
62 Correct 73 ms 8456 KB Output is correct
63 Correct 73 ms 8444 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 46 ms 8552 KB Output is correct
2 Correct 46 ms 8560 KB Output is correct
3 Correct 51 ms 8584 KB Output is correct
4 Correct 46 ms 8592 KB Output is correct
5 Correct 46 ms 8712 KB Output is correct
6 Correct 45 ms 8608 KB Output is correct
7 Correct 45 ms 8612 KB Output is correct
8 Correct 45 ms 8568 KB Output is correct
9 Correct 46 ms 8528 KB Output is correct
10 Correct 45 ms 8616 KB Output is correct
11 Correct 46 ms 8580 KB Output is correct
12 Correct 53 ms 8612 KB Output is correct
13 Correct 46 ms 8600 KB Output is correct
14 Correct 46 ms 8612 KB Output is correct
15 Correct 46 ms 8612 KB Output is correct
16 Correct 46 ms 8568 KB Output is correct
17 Correct 45 ms 8608 KB Output is correct
18 Correct 46 ms 8520 KB Output is correct
19 Correct 45 ms 8552 KB Output is correct
20 Correct 45 ms 8616 KB Output is correct
21 Correct 49 ms 8544 KB Output is correct
22 Correct 48 ms 8472 KB Output is correct
23 Correct 56 ms 8476 KB Output is correct
24 Correct 48 ms 8480 KB Output is correct
25 Correct 48 ms 8456 KB Output is correct
26 Correct 50 ms 8376 KB Output is correct
27 Correct 48 ms 8480 KB Output is correct
28 Correct 49 ms 8452 KB Output is correct
29 Correct 48 ms 8472 KB Output is correct
30 Correct 48 ms 8464 KB Output is correct
31 Correct 58 ms 8436 KB Output is correct
32 Correct 49 ms 8480 KB Output is correct
33 Correct 47 ms 8460 KB Output is correct
34 Correct 47 ms 8476 KB Output is correct
35 Correct 47 ms 8508 KB Output is correct
36 Correct 47 ms 8496 KB Output is correct
37 Correct 48 ms 8420 KB Output is correct
38 Correct 47 ms 8472 KB Output is correct
39 Correct 48 ms 8492 KB Output is correct
40 Correct 49 ms 8480 KB Output is correct
41 Correct 48 ms 8460 KB Output is correct
42 Correct 47 ms 8484 KB Output is correct
43 Correct 74 ms 8432 KB Output is correct
44 Correct 74 ms 8472 KB Output is correct
45 Correct 76 ms 8464 KB Output is correct
46 Correct 73 ms 8452 KB Output is correct
47 Correct 80 ms 8444 KB Output is correct
48 Correct 75 ms 8440 KB Output is correct
49 Correct 73 ms 8432 KB Output is correct
50 Correct 76 ms 8492 KB Output is correct
51 Correct 74 ms 8428 KB Output is correct
52 Correct 80 ms 8452 KB Output is correct
53 Correct 76 ms 8452 KB Output is correct
54 Correct 77 ms 8436 KB Output is correct
55 Correct 74 ms 8440 KB Output is correct
56 Correct 74 ms 8452 KB Output is correct
57 Correct 73 ms 8428 KB Output is correct
58 Correct 79 ms 8452 KB Output is correct
59 Correct 76 ms 8444 KB Output is correct
60 Correct 80 ms 8452 KB Output is correct
61 Correct 74 ms 8420 KB Output is correct
62 Correct 73 ms 8456 KB Output is correct
63 Correct 73 ms 8444 KB Output is correct
64 Correct 350 ms 8468 KB Output is correct
65 Correct 354 ms 8424 KB Output is correct
66 Correct 350 ms 8476 KB Output is correct
67 Correct 347 ms 8464 KB Output is correct
68 Correct 347 ms 8568 KB Output is correct
69 Correct 348 ms 8440 KB Output is correct
70 Correct 360 ms 8468 KB Output is correct
71 Correct 347 ms 8456 KB Output is correct
72 Correct 358 ms 8508 KB Output is correct
73 Correct 348 ms 8444 KB Output is correct
74 Correct 356 ms 8532 KB Output is correct
75 Correct 353 ms 8436 KB Output is correct
76 Correct 348 ms 8440 KB Output is correct
77 Correct 347 ms 8472 KB Output is correct
78 Correct 347 ms 8428 KB Output is correct
79 Correct 365 ms 8436 KB Output is correct
80 Correct 350 ms 8436 KB Output is correct
81 Correct 358 ms 8544 KB Output is correct
82 Correct 347 ms 8436 KB Output is correct
83 Correct 352 ms 8424 KB Output is correct
84 Correct 350 ms 8460 KB Output is correct