Submission #967997

# Submission time Handle Problem Language Result Execution time Memory
967997 2024-04-23T06:46:43 Z Gromp15 Binaria (CCO23_day1problem1) C++17
25 / 25
230 ms 106144 KB
#include <bits/stdc++.h>
#define ll long long
#define ar array
#define db double
#define all(x) x.begin(), x.end()
#define sz(x) (int)x.size()
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define rint(l, r) uniform_int_distribution<int>(l, r)(rng)
template<typename T> bool ckmin(T &a, const T &b) { return a > b ? a = b, 1 : 0; }
template<typename T> bool ckmax(T &a, const T &b) { return a < b ? a = b, 1 : 0; }
const int mod = 1e6 + 3;
void fadd(int &a, int b) {
	a += b;
	if (a >= mod) a -= mod;
}
int binpow(int a, int b) {
	int r = 1;
	for (; b; a = (ll)a*a%mod, b >>= 1) if (b & 1) r = (ll)r*a%mod;
	return r;
}
vector<int> facs, invfacs;
void init(int n) {
	facs.resize(n+1), invfacs.resize(n+1);
	facs[0] = 1;
	for (int i = 1; i <= n; i++) facs[i] = (ll)facs[i-1] * i % mod;
	invfacs[n] = binpow(facs[n], mod - 2);
	for (int i = n - 1; i >= 0; i--) invfacs[i] = (ll)invfacs[i+1] * (i+1) % mod;
}
int choose(int a, int b) {
	return ((ll)facs[a] * invfacs[b] % mod) * invfacs[a-b] % mod;
}
void test_case() {
	int n, k;
	cin >> n >> k;
	vector<int> a(n - k + 1);
	for (int &x : a) cin >> x;
	vector<vector<ar<int, 2>>> adj(n);
	for (int i = 0; i < n-k; i++) {
		int w = a[i+1] - a[i];
		adj[i].push_back({i + k, w});
		adj[i + k].push_back({i, -w});
	}
	vector<int> col(n);
	vector<bool> vis(n);
	auto dfs = [&](auto&& s, int v) -> void {
		vis[v] = 1;
		for (auto [u, w] : adj[v]) {
			if (!vis[u]) {
				col[u] = col[v] + w;
				s(s, u);
			}
			assert(col[u] == (col[v] + w));
		}
	};
	for (int i = 0; i < n; i++) if (!vis[i]) dfs(dfs, i);
	vector<int> state(k, -1);
	for (int i = 0; i < k; i++) {
		int b = 0;
		for (int j = i + k; j < n; j += k) {
			if (abs(col[j]) > 1) {
				cout << 0 << '\n'; return;
			}
			if (col[j] < 0) b |= 1;
			if (col[j] > 0) b |= 2;
		}
		if (b == 3) {
			cout << 0 << '\n'; return;
		}
		if (b == 1) state[i] = 1;
		if (b == 2) state[i] = 0;
	}
	ar<int, 3> who{};
	for (int i = 0; i < k; i++) {
		if (state[i] == -1) who[2]++;
		else if (state[i] == 0) who[0]++;
		else who[1]++;
	}
	if (who[1] > a[0] || who[2] + who[1] < a[0]) {
		cout << 0 << '\n'; return;
	}
	cout << choose(who[2], a[0] - who[1]) << '\n';


}
int main() {
    cin.tie(0)->sync_with_stdio(0);
	init(1e6);
    int t = 1;
//    cin >> t;
    while (t--) test_case();
}

# Verdict Execution time Memory Grader output
1 Correct 14 ms 8284 KB Output is correct
2 Correct 14 ms 8284 KB Output is correct
3 Correct 15 ms 8300 KB Output is correct
4 Correct 15 ms 8284 KB Output is correct
5 Correct 15 ms 8284 KB Output is correct
6 Correct 14 ms 8284 KB Output is correct
7 Correct 14 ms 8300 KB Output is correct
8 Correct 14 ms 8280 KB Output is correct
9 Correct 14 ms 8284 KB Output is correct
10 Correct 15 ms 8300 KB Output is correct
11 Correct 14 ms 8300 KB Output is correct
12 Correct 14 ms 8280 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 14 ms 8284 KB Output is correct
2 Correct 14 ms 8284 KB Output is correct
3 Correct 15 ms 8300 KB Output is correct
4 Correct 15 ms 8284 KB Output is correct
5 Correct 15 ms 8284 KB Output is correct
6 Correct 14 ms 8284 KB Output is correct
7 Correct 14 ms 8300 KB Output is correct
8 Correct 14 ms 8280 KB Output is correct
9 Correct 14 ms 8284 KB Output is correct
10 Correct 15 ms 8300 KB Output is correct
11 Correct 14 ms 8300 KB Output is correct
12 Correct 14 ms 8280 KB Output is correct
13 Correct 15 ms 8284 KB Output is correct
14 Correct 13 ms 8204 KB Output is correct
15 Correct 15 ms 8280 KB Output is correct
16 Correct 13 ms 8284 KB Output is correct
17 Correct 14 ms 8284 KB Output is correct
18 Correct 13 ms 8284 KB Output is correct
19 Correct 14 ms 8304 KB Output is correct
20 Correct 14 ms 8284 KB Output is correct
21 Correct 14 ms 8284 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 14 ms 8284 KB Output is correct
2 Correct 14 ms 8284 KB Output is correct
3 Correct 15 ms 8300 KB Output is correct
4 Correct 15 ms 8284 KB Output is correct
5 Correct 15 ms 8284 KB Output is correct
6 Correct 14 ms 8284 KB Output is correct
7 Correct 14 ms 8300 KB Output is correct
8 Correct 14 ms 8280 KB Output is correct
9 Correct 14 ms 8284 KB Output is correct
10 Correct 15 ms 8300 KB Output is correct
11 Correct 14 ms 8300 KB Output is correct
12 Correct 14 ms 8280 KB Output is correct
13 Correct 15 ms 8284 KB Output is correct
14 Correct 13 ms 8204 KB Output is correct
15 Correct 15 ms 8280 KB Output is correct
16 Correct 13 ms 8284 KB Output is correct
17 Correct 14 ms 8284 KB Output is correct
18 Correct 13 ms 8284 KB Output is correct
19 Correct 14 ms 8304 KB Output is correct
20 Correct 14 ms 8284 KB Output is correct
21 Correct 14 ms 8284 KB Output is correct
22 Correct 14 ms 8280 KB Output is correct
23 Correct 14 ms 8300 KB Output is correct
24 Correct 14 ms 8284 KB Output is correct
25 Correct 14 ms 8280 KB Output is correct
26 Correct 14 ms 8556 KB Output is correct
27 Correct 14 ms 8284 KB Output is correct
28 Correct 16 ms 8284 KB Output is correct
29 Correct 14 ms 8300 KB Output is correct
30 Correct 14 ms 8284 KB Output is correct
31 Correct 14 ms 8284 KB Output is correct
32 Correct 14 ms 8300 KB Output is correct
33 Correct 15 ms 8284 KB Output is correct
34 Correct 14 ms 8304 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 14 ms 8284 KB Output is correct
2 Correct 14 ms 8284 KB Output is correct
3 Correct 15 ms 8300 KB Output is correct
4 Correct 15 ms 8284 KB Output is correct
5 Correct 15 ms 8284 KB Output is correct
6 Correct 14 ms 8284 KB Output is correct
7 Correct 14 ms 8300 KB Output is correct
8 Correct 14 ms 8280 KB Output is correct
9 Correct 14 ms 8284 KB Output is correct
10 Correct 15 ms 8300 KB Output is correct
11 Correct 14 ms 8300 KB Output is correct
12 Correct 14 ms 8280 KB Output is correct
13 Correct 15 ms 8284 KB Output is correct
14 Correct 13 ms 8204 KB Output is correct
15 Correct 15 ms 8280 KB Output is correct
16 Correct 13 ms 8284 KB Output is correct
17 Correct 14 ms 8284 KB Output is correct
18 Correct 13 ms 8284 KB Output is correct
19 Correct 14 ms 8304 KB Output is correct
20 Correct 14 ms 8284 KB Output is correct
21 Correct 14 ms 8284 KB Output is correct
22 Correct 14 ms 8280 KB Output is correct
23 Correct 14 ms 8300 KB Output is correct
24 Correct 14 ms 8284 KB Output is correct
25 Correct 14 ms 8280 KB Output is correct
26 Correct 14 ms 8556 KB Output is correct
27 Correct 14 ms 8284 KB Output is correct
28 Correct 16 ms 8284 KB Output is correct
29 Correct 14 ms 8300 KB Output is correct
30 Correct 14 ms 8284 KB Output is correct
31 Correct 14 ms 8284 KB Output is correct
32 Correct 14 ms 8300 KB Output is correct
33 Correct 15 ms 8284 KB Output is correct
34 Correct 14 ms 8304 KB Output is correct
35 Correct 179 ms 72784 KB Output is correct
36 Correct 169 ms 72532 KB Output is correct
37 Correct 174 ms 72788 KB Output is correct
38 Correct 176 ms 72788 KB Output is correct
39 Correct 163 ms 72608 KB Output is correct
40 Correct 172 ms 72788 KB Output is correct
41 Correct 161 ms 72788 KB Output is correct
42 Correct 162 ms 73552 KB Output is correct
43 Correct 158 ms 72984 KB Output is correct
44 Correct 152 ms 106080 KB Output is correct
45 Correct 164 ms 106144 KB Output is correct
46 Correct 153 ms 106068 KB Output is correct
47 Correct 151 ms 88500 KB Output is correct
48 Correct 161 ms 72788 KB Output is correct
49 Correct 169 ms 72788 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 14 ms 8284 KB Output is correct
2 Correct 14 ms 8284 KB Output is correct
3 Correct 15 ms 8300 KB Output is correct
4 Correct 15 ms 8284 KB Output is correct
5 Correct 15 ms 8284 KB Output is correct
6 Correct 14 ms 8284 KB Output is correct
7 Correct 14 ms 8300 KB Output is correct
8 Correct 14 ms 8280 KB Output is correct
9 Correct 14 ms 8284 KB Output is correct
10 Correct 15 ms 8300 KB Output is correct
11 Correct 14 ms 8300 KB Output is correct
12 Correct 14 ms 8280 KB Output is correct
13 Correct 15 ms 8284 KB Output is correct
14 Correct 13 ms 8204 KB Output is correct
15 Correct 15 ms 8280 KB Output is correct
16 Correct 13 ms 8284 KB Output is correct
17 Correct 14 ms 8284 KB Output is correct
18 Correct 13 ms 8284 KB Output is correct
19 Correct 14 ms 8304 KB Output is correct
20 Correct 14 ms 8284 KB Output is correct
21 Correct 14 ms 8284 KB Output is correct
22 Correct 14 ms 8280 KB Output is correct
23 Correct 14 ms 8300 KB Output is correct
24 Correct 14 ms 8284 KB Output is correct
25 Correct 14 ms 8280 KB Output is correct
26 Correct 14 ms 8556 KB Output is correct
27 Correct 14 ms 8284 KB Output is correct
28 Correct 16 ms 8284 KB Output is correct
29 Correct 14 ms 8300 KB Output is correct
30 Correct 14 ms 8284 KB Output is correct
31 Correct 14 ms 8284 KB Output is correct
32 Correct 14 ms 8300 KB Output is correct
33 Correct 15 ms 8284 KB Output is correct
34 Correct 14 ms 8304 KB Output is correct
35 Correct 179 ms 72784 KB Output is correct
36 Correct 169 ms 72532 KB Output is correct
37 Correct 174 ms 72788 KB Output is correct
38 Correct 176 ms 72788 KB Output is correct
39 Correct 163 ms 72608 KB Output is correct
40 Correct 172 ms 72788 KB Output is correct
41 Correct 161 ms 72788 KB Output is correct
42 Correct 162 ms 73552 KB Output is correct
43 Correct 158 ms 72984 KB Output is correct
44 Correct 152 ms 106080 KB Output is correct
45 Correct 164 ms 106144 KB Output is correct
46 Correct 153 ms 106068 KB Output is correct
47 Correct 151 ms 88500 KB Output is correct
48 Correct 161 ms 72788 KB Output is correct
49 Correct 169 ms 72788 KB Output is correct
50 Correct 205 ms 71020 KB Output is correct
51 Correct 203 ms 70992 KB Output is correct
52 Correct 221 ms 70996 KB Output is correct
53 Correct 230 ms 70996 KB Output is correct
54 Correct 202 ms 70992 KB Output is correct
55 Correct 205 ms 70816 KB Output is correct
56 Correct 203 ms 70996 KB Output is correct
57 Correct 207 ms 71196 KB Output is correct
58 Correct 202 ms 71000 KB Output is correct
59 Correct 204 ms 71024 KB Output is correct
60 Correct 216 ms 70812 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 14 ms 8284 KB Output is correct
2 Correct 14 ms 8284 KB Output is correct
3 Correct 15 ms 8300 KB Output is correct
4 Correct 15 ms 8284 KB Output is correct
5 Correct 15 ms 8284 KB Output is correct
6 Correct 14 ms 8284 KB Output is correct
7 Correct 14 ms 8300 KB Output is correct
8 Correct 14 ms 8280 KB Output is correct
9 Correct 14 ms 8284 KB Output is correct
10 Correct 15 ms 8300 KB Output is correct
11 Correct 14 ms 8300 KB Output is correct
12 Correct 14 ms 8280 KB Output is correct
13 Correct 15 ms 8284 KB Output is correct
14 Correct 13 ms 8204 KB Output is correct
15 Correct 15 ms 8280 KB Output is correct
16 Correct 13 ms 8284 KB Output is correct
17 Correct 14 ms 8284 KB Output is correct
18 Correct 13 ms 8284 KB Output is correct
19 Correct 14 ms 8304 KB Output is correct
20 Correct 14 ms 8284 KB Output is correct
21 Correct 14 ms 8284 KB Output is correct
22 Correct 14 ms 8280 KB Output is correct
23 Correct 14 ms 8300 KB Output is correct
24 Correct 14 ms 8284 KB Output is correct
25 Correct 14 ms 8280 KB Output is correct
26 Correct 14 ms 8556 KB Output is correct
27 Correct 14 ms 8284 KB Output is correct
28 Correct 16 ms 8284 KB Output is correct
29 Correct 14 ms 8300 KB Output is correct
30 Correct 14 ms 8284 KB Output is correct
31 Correct 14 ms 8284 KB Output is correct
32 Correct 14 ms 8300 KB Output is correct
33 Correct 15 ms 8284 KB Output is correct
34 Correct 14 ms 8304 KB Output is correct
35 Correct 179 ms 72784 KB Output is correct
36 Correct 169 ms 72532 KB Output is correct
37 Correct 174 ms 72788 KB Output is correct
38 Correct 176 ms 72788 KB Output is correct
39 Correct 163 ms 72608 KB Output is correct
40 Correct 172 ms 72788 KB Output is correct
41 Correct 161 ms 72788 KB Output is correct
42 Correct 162 ms 73552 KB Output is correct
43 Correct 158 ms 72984 KB Output is correct
44 Correct 152 ms 106080 KB Output is correct
45 Correct 164 ms 106144 KB Output is correct
46 Correct 153 ms 106068 KB Output is correct
47 Correct 151 ms 88500 KB Output is correct
48 Correct 161 ms 72788 KB Output is correct
49 Correct 169 ms 72788 KB Output is correct
50 Correct 205 ms 71020 KB Output is correct
51 Correct 203 ms 70992 KB Output is correct
52 Correct 221 ms 70996 KB Output is correct
53 Correct 230 ms 70996 KB Output is correct
54 Correct 202 ms 70992 KB Output is correct
55 Correct 205 ms 70816 KB Output is correct
56 Correct 203 ms 70996 KB Output is correct
57 Correct 207 ms 71196 KB Output is correct
58 Correct 202 ms 71000 KB Output is correct
59 Correct 204 ms 71024 KB Output is correct
60 Correct 216 ms 70812 KB Output is correct
61 Correct 26 ms 39516 KB Output is correct
62 Correct 25 ms 39516 KB Output is correct
63 Correct 26 ms 39508 KB Output is correct
64 Correct 26 ms 39656 KB Output is correct
65 Correct 97 ms 70960 KB Output is correct
66 Correct 83 ms 61388 KB Output is correct
67 Correct 132 ms 70808 KB Output is correct
68 Correct 38 ms 45308 KB Output is correct
69 Correct 26 ms 39532 KB Output is correct
70 Correct 26 ms 39516 KB Output is correct
71 Correct 25 ms 39504 KB Output is correct