답안 #882934

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
882934 2023-12-04T07:53:00 Z tsumondai Binaria (CCO23_day1problem1) C++14
25 / 25
81 ms 37204 KB
#include <bits/stdc++.h>
using namespace std;

#define int long long
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define foru(i, l, r) for(int i = l; i <= r; i++)
#define ford(i, r, l) for(int i = r; i >= l; i--)
#define __TIME  (1.0 * clock() / CLOCKS_PER_SEC)

typedef pair<int, int> ii;
typedef pair<ii, int> iii;
typedef pair<ii, ii> iiii;

const int N = 1e6 + 5;

const int oo = 1e9, mod = 1e6 + 3;

int n, m, k, fact[N], inv[N], a[N], color[N];
string s;
vector<int> arr;

long long binpow(long long a, long long b) {
	a %= mod;
	long long res = 1;
	while (b > 0) {
		if (b & 1)
			res = res * a % mod;
		a = a * a % mod;
		b >>= 1;
	}
	return res;
}

int comb(int k, int n) {
	if (k > n || k < 0) return 0;
	return (fact[n] * ((inv[k] * inv[n - k]) % mod)) % mod;
}

void process() {
	cin >> n >> k;
	foru(i, 1, n - k + 1) cin >> a[i];
	fact[0] = inv[0] = 1;
	foru(i, 1, n) fact[i] = (fact[i - 1] * i) % mod;
	inv[n] = binpow(fact[n], mod - 2);
	ford(i, n - 1, 1) inv[i] = (inv[i + 1] * (i + 1)) % mod;
	foru(i, 1, n) color[i] = 2;
	ford(i, n - k, 1) {
		if (abs(a[i] - a[i + 1]) > 1) {
			cout << 0 << '\n'; return;
		}
		if (a[i] == a[i + 1]) color[i] = color[i + k];
		else if (a[i] > a[i + 1]) {
			if (color[i + k] == 1) {
				cout << 0 << '\n'; return;
			}
			color[i] = 1;
		} else {
			if (color[i + k] == 0) {
				cout << 0 << '\n'; return;
			}
			color[i] = 0;
		}

	}

	int ans = 0;
	foru(i, 1, k) a[1] -= (color[i] == 1), ans += color[i] == 2;
	cout << comb(a[1], ans);
	return;
}

signed main() {
	cin.tie(0)->sync_with_stdio(false);
	//freopen(".inp", "r", stdin);
	//freopen(".out", "w", stdout);
	process();
	cerr << "Time elapsed: " << __TIME << " s.\n";
	return 0;
}

/*
Xét các trường hợp đặc biệt
Kiểm tra lại input/output
Cố gắng trâu
Lật ngược bài toán
Keep calm and get VOI
Flow:

*/
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 6488 KB Output is correct
2 Correct 1 ms 6492 KB Output is correct
3 Correct 1 ms 6492 KB Output is correct
4 Correct 1 ms 6492 KB Output is correct
5 Correct 1 ms 6488 KB Output is correct
6 Correct 1 ms 6492 KB Output is correct
7 Correct 1 ms 6488 KB Output is correct
8 Correct 1 ms 6492 KB Output is correct
9 Correct 1 ms 6492 KB Output is correct
10 Correct 1 ms 6492 KB Output is correct
11 Correct 1 ms 6492 KB Output is correct
12 Correct 1 ms 6492 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 6488 KB Output is correct
2 Correct 1 ms 6492 KB Output is correct
3 Correct 1 ms 6492 KB Output is correct
4 Correct 1 ms 6492 KB Output is correct
5 Correct 1 ms 6488 KB Output is correct
6 Correct 1 ms 6492 KB Output is correct
7 Correct 1 ms 6488 KB Output is correct
8 Correct 1 ms 6492 KB Output is correct
9 Correct 1 ms 6492 KB Output is correct
10 Correct 1 ms 6492 KB Output is correct
11 Correct 1 ms 6492 KB Output is correct
12 Correct 1 ms 6492 KB Output is correct
13 Correct 1 ms 6492 KB Output is correct
14 Correct 1 ms 6492 KB Output is correct
15 Correct 2 ms 6492 KB Output is correct
16 Correct 1 ms 6492 KB Output is correct
17 Correct 1 ms 6492 KB Output is correct
18 Correct 1 ms 6744 KB Output is correct
19 Correct 1 ms 6492 KB Output is correct
20 Correct 1 ms 6492 KB Output is correct
21 Correct 1 ms 6612 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 6488 KB Output is correct
2 Correct 1 ms 6492 KB Output is correct
3 Correct 1 ms 6492 KB Output is correct
4 Correct 1 ms 6492 KB Output is correct
5 Correct 1 ms 6488 KB Output is correct
6 Correct 1 ms 6492 KB Output is correct
7 Correct 1 ms 6488 KB Output is correct
8 Correct 1 ms 6492 KB Output is correct
9 Correct 1 ms 6492 KB Output is correct
10 Correct 1 ms 6492 KB Output is correct
11 Correct 1 ms 6492 KB Output is correct
12 Correct 1 ms 6492 KB Output is correct
13 Correct 1 ms 6492 KB Output is correct
14 Correct 1 ms 6492 KB Output is correct
15 Correct 2 ms 6492 KB Output is correct
16 Correct 1 ms 6492 KB Output is correct
17 Correct 1 ms 6492 KB Output is correct
18 Correct 1 ms 6744 KB Output is correct
19 Correct 1 ms 6492 KB Output is correct
20 Correct 1 ms 6492 KB Output is correct
21 Correct 1 ms 6612 KB Output is correct
22 Correct 1 ms 6492 KB Output is correct
23 Correct 1 ms 6492 KB Output is correct
24 Correct 1 ms 6492 KB Output is correct
25 Correct 1 ms 6492 KB Output is correct
26 Correct 1 ms 6492 KB Output is correct
27 Correct 1 ms 6492 KB Output is correct
28 Correct 1 ms 6492 KB Output is correct
29 Correct 1 ms 6492 KB Output is correct
30 Correct 1 ms 6492 KB Output is correct
31 Correct 1 ms 6492 KB Output is correct
32 Correct 1 ms 6492 KB Output is correct
33 Correct 2 ms 6492 KB Output is correct
34 Correct 1 ms 6492 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 6488 KB Output is correct
2 Correct 1 ms 6492 KB Output is correct
3 Correct 1 ms 6492 KB Output is correct
4 Correct 1 ms 6492 KB Output is correct
5 Correct 1 ms 6488 KB Output is correct
6 Correct 1 ms 6492 KB Output is correct
7 Correct 1 ms 6488 KB Output is correct
8 Correct 1 ms 6492 KB Output is correct
9 Correct 1 ms 6492 KB Output is correct
10 Correct 1 ms 6492 KB Output is correct
11 Correct 1 ms 6492 KB Output is correct
12 Correct 1 ms 6492 KB Output is correct
13 Correct 1 ms 6492 KB Output is correct
14 Correct 1 ms 6492 KB Output is correct
15 Correct 2 ms 6492 KB Output is correct
16 Correct 1 ms 6492 KB Output is correct
17 Correct 1 ms 6492 KB Output is correct
18 Correct 1 ms 6744 KB Output is correct
19 Correct 1 ms 6492 KB Output is correct
20 Correct 1 ms 6492 KB Output is correct
21 Correct 1 ms 6612 KB Output is correct
22 Correct 1 ms 6492 KB Output is correct
23 Correct 1 ms 6492 KB Output is correct
24 Correct 1 ms 6492 KB Output is correct
25 Correct 1 ms 6492 KB Output is correct
26 Correct 1 ms 6492 KB Output is correct
27 Correct 1 ms 6492 KB Output is correct
28 Correct 1 ms 6492 KB Output is correct
29 Correct 1 ms 6492 KB Output is correct
30 Correct 1 ms 6492 KB Output is correct
31 Correct 1 ms 6492 KB Output is correct
32 Correct 1 ms 6492 KB Output is correct
33 Correct 2 ms 6492 KB Output is correct
34 Correct 1 ms 6492 KB Output is correct
35 Correct 54 ms 33620 KB Output is correct
36 Correct 58 ms 34120 KB Output is correct
37 Correct 60 ms 34496 KB Output is correct
38 Correct 70 ms 34500 KB Output is correct
39 Correct 57 ms 33620 KB Output is correct
40 Correct 68 ms 34644 KB Output is correct
41 Correct 60 ms 34644 KB Output is correct
42 Correct 55 ms 33620 KB Output is correct
43 Correct 55 ms 33620 KB Output is correct
44 Correct 56 ms 33620 KB Output is correct
45 Correct 65 ms 33620 KB Output is correct
46 Correct 57 ms 33516 KB Output is correct
47 Correct 63 ms 33620 KB Output is correct
48 Correct 58 ms 34644 KB Output is correct
49 Correct 70 ms 34652 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 6488 KB Output is correct
2 Correct 1 ms 6492 KB Output is correct
3 Correct 1 ms 6492 KB Output is correct
4 Correct 1 ms 6492 KB Output is correct
5 Correct 1 ms 6488 KB Output is correct
6 Correct 1 ms 6492 KB Output is correct
7 Correct 1 ms 6488 KB Output is correct
8 Correct 1 ms 6492 KB Output is correct
9 Correct 1 ms 6492 KB Output is correct
10 Correct 1 ms 6492 KB Output is correct
11 Correct 1 ms 6492 KB Output is correct
12 Correct 1 ms 6492 KB Output is correct
13 Correct 1 ms 6492 KB Output is correct
14 Correct 1 ms 6492 KB Output is correct
15 Correct 2 ms 6492 KB Output is correct
16 Correct 1 ms 6492 KB Output is correct
17 Correct 1 ms 6492 KB Output is correct
18 Correct 1 ms 6744 KB Output is correct
19 Correct 1 ms 6492 KB Output is correct
20 Correct 1 ms 6492 KB Output is correct
21 Correct 1 ms 6612 KB Output is correct
22 Correct 1 ms 6492 KB Output is correct
23 Correct 1 ms 6492 KB Output is correct
24 Correct 1 ms 6492 KB Output is correct
25 Correct 1 ms 6492 KB Output is correct
26 Correct 1 ms 6492 KB Output is correct
27 Correct 1 ms 6492 KB Output is correct
28 Correct 1 ms 6492 KB Output is correct
29 Correct 1 ms 6492 KB Output is correct
30 Correct 1 ms 6492 KB Output is correct
31 Correct 1 ms 6492 KB Output is correct
32 Correct 1 ms 6492 KB Output is correct
33 Correct 2 ms 6492 KB Output is correct
34 Correct 1 ms 6492 KB Output is correct
35 Correct 54 ms 33620 KB Output is correct
36 Correct 58 ms 34120 KB Output is correct
37 Correct 60 ms 34496 KB Output is correct
38 Correct 70 ms 34500 KB Output is correct
39 Correct 57 ms 33620 KB Output is correct
40 Correct 68 ms 34644 KB Output is correct
41 Correct 60 ms 34644 KB Output is correct
42 Correct 55 ms 33620 KB Output is correct
43 Correct 55 ms 33620 KB Output is correct
44 Correct 56 ms 33620 KB Output is correct
45 Correct 65 ms 33620 KB Output is correct
46 Correct 57 ms 33516 KB Output is correct
47 Correct 63 ms 33620 KB Output is correct
48 Correct 58 ms 34644 KB Output is correct
49 Correct 70 ms 34652 KB Output is correct
50 Correct 72 ms 36416 KB Output is correct
51 Correct 70 ms 36548 KB Output is correct
52 Correct 78 ms 36436 KB Output is correct
53 Correct 74 ms 36544 KB Output is correct
54 Correct 81 ms 36436 KB Output is correct
55 Correct 69 ms 36436 KB Output is correct
56 Correct 77 ms 36436 KB Output is correct
57 Correct 65 ms 35532 KB Output is correct
58 Correct 72 ms 36540 KB Output is correct
59 Correct 69 ms 36432 KB Output is correct
60 Correct 68 ms 35664 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 6488 KB Output is correct
2 Correct 1 ms 6492 KB Output is correct
3 Correct 1 ms 6492 KB Output is correct
4 Correct 1 ms 6492 KB Output is correct
5 Correct 1 ms 6488 KB Output is correct
6 Correct 1 ms 6492 KB Output is correct
7 Correct 1 ms 6488 KB Output is correct
8 Correct 1 ms 6492 KB Output is correct
9 Correct 1 ms 6492 KB Output is correct
10 Correct 1 ms 6492 KB Output is correct
11 Correct 1 ms 6492 KB Output is correct
12 Correct 1 ms 6492 KB Output is correct
13 Correct 1 ms 6492 KB Output is correct
14 Correct 1 ms 6492 KB Output is correct
15 Correct 2 ms 6492 KB Output is correct
16 Correct 1 ms 6492 KB Output is correct
17 Correct 1 ms 6492 KB Output is correct
18 Correct 1 ms 6744 KB Output is correct
19 Correct 1 ms 6492 KB Output is correct
20 Correct 1 ms 6492 KB Output is correct
21 Correct 1 ms 6612 KB Output is correct
22 Correct 1 ms 6492 KB Output is correct
23 Correct 1 ms 6492 KB Output is correct
24 Correct 1 ms 6492 KB Output is correct
25 Correct 1 ms 6492 KB Output is correct
26 Correct 1 ms 6492 KB Output is correct
27 Correct 1 ms 6492 KB Output is correct
28 Correct 1 ms 6492 KB Output is correct
29 Correct 1 ms 6492 KB Output is correct
30 Correct 1 ms 6492 KB Output is correct
31 Correct 1 ms 6492 KB Output is correct
32 Correct 1 ms 6492 KB Output is correct
33 Correct 2 ms 6492 KB Output is correct
34 Correct 1 ms 6492 KB Output is correct
35 Correct 54 ms 33620 KB Output is correct
36 Correct 58 ms 34120 KB Output is correct
37 Correct 60 ms 34496 KB Output is correct
38 Correct 70 ms 34500 KB Output is correct
39 Correct 57 ms 33620 KB Output is correct
40 Correct 68 ms 34644 KB Output is correct
41 Correct 60 ms 34644 KB Output is correct
42 Correct 55 ms 33620 KB Output is correct
43 Correct 55 ms 33620 KB Output is correct
44 Correct 56 ms 33620 KB Output is correct
45 Correct 65 ms 33620 KB Output is correct
46 Correct 57 ms 33516 KB Output is correct
47 Correct 63 ms 33620 KB Output is correct
48 Correct 58 ms 34644 KB Output is correct
49 Correct 70 ms 34652 KB Output is correct
50 Correct 72 ms 36416 KB Output is correct
51 Correct 70 ms 36548 KB Output is correct
52 Correct 78 ms 36436 KB Output is correct
53 Correct 74 ms 36544 KB Output is correct
54 Correct 81 ms 36436 KB Output is correct
55 Correct 69 ms 36436 KB Output is correct
56 Correct 77 ms 36436 KB Output is correct
57 Correct 65 ms 35532 KB Output is correct
58 Correct 72 ms 36540 KB Output is correct
59 Correct 69 ms 36432 KB Output is correct
60 Correct 68 ms 35664 KB Output is correct
61 Correct 18 ms 25436 KB Output is correct
62 Correct 20 ms 25412 KB Output is correct
63 Correct 20 ms 25428 KB Output is correct
64 Correct 17 ms 25436 KB Output is correct
65 Correct 51 ms 32972 KB Output is correct
66 Correct 40 ms 31944 KB Output is correct
67 Correct 69 ms 37204 KB Output is correct
68 Correct 23 ms 27988 KB Output is correct
69 Correct 17 ms 25564 KB Output is correct
70 Correct 17 ms 25428 KB Output is correct
71 Correct 17 ms 25436 KB Output is correct