Submission #792397

# Submission time Handle Problem Language Result Execution time Memory
792397 2023-07-25T04:07:11 Z GEN 이지후(#10086) Binaria (CCO23_day1problem1) C++17
25 / 25
67 ms 8196 KB
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
using pi = array<int, 2>;
#define sz(v) ((int)(v).size())
#define all(v) (v).begin(), (v).end()
using llf = long double;
const int mod = 1e6 + 3; // 1e9 + 7;//993244853;

// I don't remember the credit of modint, but it's not mine.
// I don't remember the credit of FFT, but it's probably mine.
// Polynomial library is due to adamant:
// https://github.com/cp-algorithms/cp-algorithms-aux/blob/master/src/polynomial.cpp
// To use polynomial sqrt, need to amend sqrt for modint.

struct mint {
	int val;
	mint() { val = 0; }
	mint(const lint &v) {
		val = (-mod <= v && v < mod) ? v : v % mod;
		if (val < 0)
			val += mod;
	}

	friend ostream &operator<<(ostream &os, const mint &a) { return os << a.val; }
	friend bool operator==(const mint &a, const mint &b) { return a.val == b.val; }
	friend bool operator!=(const mint &a, const mint &b) { return !(a == b); }
	friend bool operator<(const mint &a, const mint &b) { return a.val < b.val; }

	mint operator-() const { return mint(-val); }
	mint &operator+=(const mint &m) {
		if ((val += m.val) >= mod)
			val -= mod;
		return *this;
	}
	mint &operator-=(const mint &m) {
		if ((val -= m.val) < 0)
			val += mod;
		return *this;
	}
	mint &operator*=(const mint &m) {
		val = (lint)val * m.val % mod;
		return *this;
	}
	friend mint ipow(mint a, lint p) {
		mint ans = 1;
		for (; p; p /= 2, a *= a)
			if (p & 1)
				ans *= a;
		return ans;
	}
	mint inv() const { return ipow(*this, mod - 2); }
	mint &operator/=(const mint &m) { return (*this) *= m.inv(); }

	friend mint operator+(mint a, const mint &b) { return a += b; }
	friend mint operator-(mint a, const mint &b) { return a -= b; }
	friend mint operator*(mint a, const mint &b) { return a *= b; }
	friend mint operator/(mint a, const mint &b) { return a /= b; }
	operator int64_t() const { return val; }
};

mint bino(int n, int k) {
	mint up = 1, dn = 1;
	for (int i = 0; i < k; i++) {
		up *= mint(n - i);
		dn *= mint(i + 1);
	}
	return up / dn;
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int n, k;
	cin >> n >> k;
	vector<int> a(n - k + 1);
	for (int i = 0; i < n - k + 1; i++)
		cin >> a[i];
	vector<int> d(n);
	for (int i = 0; i + k < n; i++) {
		d[i + k] = d[i] + a[i + 1] - a[i];
	}
	int free = 0;
	for (int i = 0; i < k; i++) {
		int lo = 1e9;
		for (int j = i; j < n; j += k) {
			lo = min(lo, d[j]);
		}
		int hi = 0;
		for (int j = i; j < n; j += k) {
			d[j] -= lo;
			hi = max(d[j], hi);
		}
		if (hi >= 2) {
			cout << "0\n";
			return 0;
		}
		if (hi == 0) {
			free++;
		}
	}
	int ks = a[0] - accumulate(d.begin(), d.begin() + k, 0);
	if (ks < 0 || ks > free) {
		cout << "0\n";
		return 0;
	}
	cout << bino(free, ks) << "\n";
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 284 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 284 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 0 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 284 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 0 ms 212 KB Output is correct
22 Correct 0 ms 212 KB Output is correct
23 Correct 0 ms 212 KB Output is correct
24 Correct 1 ms 212 KB Output is correct
25 Correct 0 ms 212 KB Output is correct
26 Correct 0 ms 212 KB Output is correct
27 Correct 0 ms 212 KB Output is correct
28 Correct 1 ms 328 KB Output is correct
29 Correct 0 ms 212 KB Output is correct
30 Correct 0 ms 212 KB Output is correct
31 Correct 0 ms 212 KB Output is correct
32 Correct 0 ms 212 KB Output is correct
33 Correct 0 ms 212 KB Output is correct
34 Correct 0 ms 276 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 284 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 0 ms 212 KB Output is correct
22 Correct 0 ms 212 KB Output is correct
23 Correct 0 ms 212 KB Output is correct
24 Correct 1 ms 212 KB Output is correct
25 Correct 0 ms 212 KB Output is correct
26 Correct 0 ms 212 KB Output is correct
27 Correct 0 ms 212 KB Output is correct
28 Correct 1 ms 328 KB Output is correct
29 Correct 0 ms 212 KB Output is correct
30 Correct 0 ms 212 KB Output is correct
31 Correct 0 ms 212 KB Output is correct
32 Correct 0 ms 212 KB Output is correct
33 Correct 0 ms 212 KB Output is correct
34 Correct 0 ms 276 KB Output is correct
35 Correct 43 ms 8080 KB Output is correct
36 Correct 47 ms 8076 KB Output is correct
37 Correct 47 ms 8076 KB Output is correct
38 Correct 51 ms 8076 KB Output is correct
39 Correct 46 ms 8140 KB Output is correct
40 Correct 49 ms 8072 KB Output is correct
41 Correct 47 ms 8076 KB Output is correct
42 Correct 43 ms 8092 KB Output is correct
43 Correct 49 ms 8080 KB Output is correct
44 Correct 46 ms 8076 KB Output is correct
45 Correct 45 ms 8072 KB Output is correct
46 Correct 45 ms 8080 KB Output is correct
47 Correct 47 ms 8076 KB Output is correct
48 Correct 47 ms 8060 KB Output is correct
49 Correct 47 ms 8012 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 284 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 0 ms 212 KB Output is correct
22 Correct 0 ms 212 KB Output is correct
23 Correct 0 ms 212 KB Output is correct
24 Correct 1 ms 212 KB Output is correct
25 Correct 0 ms 212 KB Output is correct
26 Correct 0 ms 212 KB Output is correct
27 Correct 0 ms 212 KB Output is correct
28 Correct 1 ms 328 KB Output is correct
29 Correct 0 ms 212 KB Output is correct
30 Correct 0 ms 212 KB Output is correct
31 Correct 0 ms 212 KB Output is correct
32 Correct 0 ms 212 KB Output is correct
33 Correct 0 ms 212 KB Output is correct
34 Correct 0 ms 276 KB Output is correct
35 Correct 43 ms 8080 KB Output is correct
36 Correct 47 ms 8076 KB Output is correct
37 Correct 47 ms 8076 KB Output is correct
38 Correct 51 ms 8076 KB Output is correct
39 Correct 46 ms 8140 KB Output is correct
40 Correct 49 ms 8072 KB Output is correct
41 Correct 47 ms 8076 KB Output is correct
42 Correct 43 ms 8092 KB Output is correct
43 Correct 49 ms 8080 KB Output is correct
44 Correct 46 ms 8076 KB Output is correct
45 Correct 45 ms 8072 KB Output is correct
46 Correct 45 ms 8080 KB Output is correct
47 Correct 47 ms 8076 KB Output is correct
48 Correct 47 ms 8060 KB Output is correct
49 Correct 47 ms 8012 KB Output is correct
50 Correct 56 ms 8052 KB Output is correct
51 Correct 61 ms 8068 KB Output is correct
52 Correct 60 ms 8056 KB Output is correct
53 Correct 63 ms 8064 KB Output is correct
54 Correct 56 ms 8068 KB Output is correct
55 Correct 57 ms 8068 KB Output is correct
56 Correct 55 ms 8012 KB Output is correct
57 Correct 51 ms 8064 KB Output is correct
58 Correct 67 ms 8196 KB Output is correct
59 Correct 57 ms 8012 KB Output is correct
60 Correct 51 ms 8072 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 284 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 0 ms 212 KB Output is correct
22 Correct 0 ms 212 KB Output is correct
23 Correct 0 ms 212 KB Output is correct
24 Correct 1 ms 212 KB Output is correct
25 Correct 0 ms 212 KB Output is correct
26 Correct 0 ms 212 KB Output is correct
27 Correct 0 ms 212 KB Output is correct
28 Correct 1 ms 328 KB Output is correct
29 Correct 0 ms 212 KB Output is correct
30 Correct 0 ms 212 KB Output is correct
31 Correct 0 ms 212 KB Output is correct
32 Correct 0 ms 212 KB Output is correct
33 Correct 0 ms 212 KB Output is correct
34 Correct 0 ms 276 KB Output is correct
35 Correct 43 ms 8080 KB Output is correct
36 Correct 47 ms 8076 KB Output is correct
37 Correct 47 ms 8076 KB Output is correct
38 Correct 51 ms 8076 KB Output is correct
39 Correct 46 ms 8140 KB Output is correct
40 Correct 49 ms 8072 KB Output is correct
41 Correct 47 ms 8076 KB Output is correct
42 Correct 43 ms 8092 KB Output is correct
43 Correct 49 ms 8080 KB Output is correct
44 Correct 46 ms 8076 KB Output is correct
45 Correct 45 ms 8072 KB Output is correct
46 Correct 45 ms 8080 KB Output is correct
47 Correct 47 ms 8076 KB Output is correct
48 Correct 47 ms 8060 KB Output is correct
49 Correct 47 ms 8012 KB Output is correct
50 Correct 56 ms 8052 KB Output is correct
51 Correct 61 ms 8068 KB Output is correct
52 Correct 60 ms 8056 KB Output is correct
53 Correct 63 ms 8064 KB Output is correct
54 Correct 56 ms 8068 KB Output is correct
55 Correct 57 ms 8068 KB Output is correct
56 Correct 55 ms 8012 KB Output is correct
57 Correct 51 ms 8064 KB Output is correct
58 Correct 67 ms 8196 KB Output is correct
59 Correct 57 ms 8012 KB Output is correct
60 Correct 51 ms 8072 KB Output is correct
61 Correct 7 ms 4180 KB Output is correct
62 Correct 6 ms 4180 KB Output is correct
63 Correct 9 ms 4180 KB Output is correct
64 Correct 7 ms 4180 KB Output is correct
65 Correct 39 ms 6104 KB Output is correct
66 Correct 28 ms 5528 KB Output is correct
67 Correct 54 ms 7244 KB Output is correct
68 Correct 10 ms 4564 KB Output is correct
69 Correct 9 ms 4180 KB Output is correct
70 Correct 4 ms 4180 KB Output is correct
71 Correct 7 ms 4180 KB Output is correct