// Do easier subtasks for ALL problems in IO when stuck for too long
// Don't do nothing, do something, you can do it! :)
// Try a different approach, check every approach if feasible
// Don't overthink, don't panic, clear your mind
#include<bits/stdc++.h>
#define fastcincout ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define fi first
#define se second
#define pri priority_queue
#define str string
#define int long long
#define pii pair<int, int>
#define pll pair<ll, ll>
#define pu push_back
#define po pop_back
#define all(v) v.begin(), v.end()
#define MOD 1000003
using namespace std;
const int N=1e6+5;
bool debug=0;
int n, k;
int fact[N], inv[N], a[N], b[N];
int mult(int x, int y) {
return (x*y)%MOD;
}
int pang(int x, int y) {
if (y == 0) return 1;
int t = pang(x, y/2);
t = mult(t, t);
if (y&1) return mult(t, x);
return t;
}
void prec() {
fact[0] = 1;
inv[0] = 1;
for (int i=1; i<=N-5; i++) {
fact[i] = mult(fact[i-1], i);
inv[i] = pang(fact[i], MOD-2);
}
}
int C(int M, int R) {
if (R < 0) return 0; // impossible
if (R > M) return 0;
return mult(fact[M], mult(inv[R], inv[M-R]));
}
void solve() {
prec();
cin >> n >> k;
for (int i=1; i<=n; i++) b[i] = -1;
int m = n - k + 1;
for (int i=1; i<=m; i++) cin >> a[i];
int slots = 0, ones = a[1];
bool posi = 1;
for (int i=m-1; i>=1; i--) {
int l = i, r = l+k;
if (debug) cout << "index: " << i << " -> l: " << l << " r: " << r << "\n";
if (abs(a[i] - a[i+1]) > 1) {
if (debug) cout << "Impossible difference!" << "\n";
posi = 0;
break;
}
if ( a[i] > a[i+1] ){
// we need r to be 0 and l = 1 to decrease the sum
if ( b[r] == 1 ){
posi = 0;
break;
}
b[l] = 1;
}
else if ( a[i] < a[i+1] ){
// we need l to be 0 and r = 1 to increase the sum
if ( b[r] == 0 ){
posi = 0;
break;
}
b[l] = 0;
}
else {
b[l] = b[r];
}
}
if (debug) {
cout << "B: ";
for (int i=1; i<=n; i++) cout << b[i] << " ";
cout << "\n";
}
if (!posi) {
if (debug) cout << "impossible!\n";
cout << 0 << "\n";
return;
}
for (int i=1; i<=k; i++) {
if (b[i] == 1) ones--;
if (b[i] == -1) slots++;
}
if (debug) cout << "Empty slots: " << slots << " ones: " << ones << "\n";
int ans = C(slots, ones);
cout << ans << "\n";
}
signed main() {
// freopen("Input.in", "r", stdin);
// freopen("Output.out", "w", stdout);
// freopen must have the file in the same folder as the code file
fastcincout;
int testcases=1;
// cin >> testcases;
while(testcases--)
{
solve();
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
113 ms |
19156 KB |
Output is correct |
2 |
Correct |
111 ms |
19148 KB |
Output is correct |
3 |
Correct |
112 ms |
19164 KB |
Output is correct |
4 |
Correct |
111 ms |
19028 KB |
Output is correct |
5 |
Correct |
112 ms |
19120 KB |
Output is correct |
6 |
Correct |
112 ms |
19156 KB |
Output is correct |
7 |
Correct |
112 ms |
19152 KB |
Output is correct |
8 |
Correct |
112 ms |
19144 KB |
Output is correct |
9 |
Correct |
112 ms |
19024 KB |
Output is correct |
10 |
Correct |
114 ms |
19160 KB |
Output is correct |
11 |
Correct |
112 ms |
19536 KB |
Output is correct |
12 |
Correct |
112 ms |
19028 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
113 ms |
19156 KB |
Output is correct |
2 |
Correct |
111 ms |
19148 KB |
Output is correct |
3 |
Correct |
112 ms |
19164 KB |
Output is correct |
4 |
Correct |
111 ms |
19028 KB |
Output is correct |
5 |
Correct |
112 ms |
19120 KB |
Output is correct |
6 |
Correct |
112 ms |
19156 KB |
Output is correct |
7 |
Correct |
112 ms |
19152 KB |
Output is correct |
8 |
Correct |
112 ms |
19144 KB |
Output is correct |
9 |
Correct |
112 ms |
19024 KB |
Output is correct |
10 |
Correct |
114 ms |
19160 KB |
Output is correct |
11 |
Correct |
112 ms |
19536 KB |
Output is correct |
12 |
Correct |
112 ms |
19028 KB |
Output is correct |
13 |
Correct |
112 ms |
19028 KB |
Output is correct |
14 |
Correct |
112 ms |
19140 KB |
Output is correct |
15 |
Correct |
115 ms |
19028 KB |
Output is correct |
16 |
Correct |
112 ms |
19028 KB |
Output is correct |
17 |
Correct |
112 ms |
19160 KB |
Output is correct |
18 |
Correct |
114 ms |
19148 KB |
Output is correct |
19 |
Correct |
112 ms |
19144 KB |
Output is correct |
20 |
Correct |
111 ms |
19164 KB |
Output is correct |
21 |
Correct |
111 ms |
19144 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
113 ms |
19156 KB |
Output is correct |
2 |
Correct |
111 ms |
19148 KB |
Output is correct |
3 |
Correct |
112 ms |
19164 KB |
Output is correct |
4 |
Correct |
111 ms |
19028 KB |
Output is correct |
5 |
Correct |
112 ms |
19120 KB |
Output is correct |
6 |
Correct |
112 ms |
19156 KB |
Output is correct |
7 |
Correct |
112 ms |
19152 KB |
Output is correct |
8 |
Correct |
112 ms |
19144 KB |
Output is correct |
9 |
Correct |
112 ms |
19024 KB |
Output is correct |
10 |
Correct |
114 ms |
19160 KB |
Output is correct |
11 |
Correct |
112 ms |
19536 KB |
Output is correct |
12 |
Correct |
112 ms |
19028 KB |
Output is correct |
13 |
Correct |
112 ms |
19028 KB |
Output is correct |
14 |
Correct |
112 ms |
19140 KB |
Output is correct |
15 |
Correct |
115 ms |
19028 KB |
Output is correct |
16 |
Correct |
112 ms |
19028 KB |
Output is correct |
17 |
Correct |
112 ms |
19160 KB |
Output is correct |
18 |
Correct |
114 ms |
19148 KB |
Output is correct |
19 |
Correct |
112 ms |
19144 KB |
Output is correct |
20 |
Correct |
111 ms |
19164 KB |
Output is correct |
21 |
Correct |
111 ms |
19144 KB |
Output is correct |
22 |
Correct |
116 ms |
19028 KB |
Output is correct |
23 |
Correct |
112 ms |
19024 KB |
Output is correct |
24 |
Correct |
111 ms |
19028 KB |
Output is correct |
25 |
Correct |
112 ms |
19144 KB |
Output is correct |
26 |
Correct |
111 ms |
19140 KB |
Output is correct |
27 |
Correct |
111 ms |
19164 KB |
Output is correct |
28 |
Correct |
112 ms |
19024 KB |
Output is correct |
29 |
Correct |
112 ms |
19156 KB |
Output is correct |
30 |
Correct |
111 ms |
19156 KB |
Output is correct |
31 |
Correct |
111 ms |
19144 KB |
Output is correct |
32 |
Correct |
113 ms |
19164 KB |
Output is correct |
33 |
Correct |
112 ms |
19024 KB |
Output is correct |
34 |
Correct |
112 ms |
19148 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
113 ms |
19156 KB |
Output is correct |
2 |
Correct |
111 ms |
19148 KB |
Output is correct |
3 |
Correct |
112 ms |
19164 KB |
Output is correct |
4 |
Correct |
111 ms |
19028 KB |
Output is correct |
5 |
Correct |
112 ms |
19120 KB |
Output is correct |
6 |
Correct |
112 ms |
19156 KB |
Output is correct |
7 |
Correct |
112 ms |
19152 KB |
Output is correct |
8 |
Correct |
112 ms |
19144 KB |
Output is correct |
9 |
Correct |
112 ms |
19024 KB |
Output is correct |
10 |
Correct |
114 ms |
19160 KB |
Output is correct |
11 |
Correct |
112 ms |
19536 KB |
Output is correct |
12 |
Correct |
112 ms |
19028 KB |
Output is correct |
13 |
Correct |
112 ms |
19028 KB |
Output is correct |
14 |
Correct |
112 ms |
19140 KB |
Output is correct |
15 |
Correct |
115 ms |
19028 KB |
Output is correct |
16 |
Correct |
112 ms |
19028 KB |
Output is correct |
17 |
Correct |
112 ms |
19160 KB |
Output is correct |
18 |
Correct |
114 ms |
19148 KB |
Output is correct |
19 |
Correct |
112 ms |
19144 KB |
Output is correct |
20 |
Correct |
111 ms |
19164 KB |
Output is correct |
21 |
Correct |
111 ms |
19144 KB |
Output is correct |
22 |
Correct |
116 ms |
19028 KB |
Output is correct |
23 |
Correct |
112 ms |
19024 KB |
Output is correct |
24 |
Correct |
111 ms |
19028 KB |
Output is correct |
25 |
Correct |
112 ms |
19144 KB |
Output is correct |
26 |
Correct |
111 ms |
19140 KB |
Output is correct |
27 |
Correct |
111 ms |
19164 KB |
Output is correct |
28 |
Correct |
112 ms |
19024 KB |
Output is correct |
29 |
Correct |
112 ms |
19156 KB |
Output is correct |
30 |
Correct |
111 ms |
19156 KB |
Output is correct |
31 |
Correct |
111 ms |
19144 KB |
Output is correct |
32 |
Correct |
113 ms |
19164 KB |
Output is correct |
33 |
Correct |
112 ms |
19024 KB |
Output is correct |
34 |
Correct |
112 ms |
19148 KB |
Output is correct |
35 |
Correct |
149 ms |
33616 KB |
Output is correct |
36 |
Correct |
157 ms |
34252 KB |
Output is correct |
37 |
Correct |
161 ms |
34676 KB |
Output is correct |
38 |
Correct |
162 ms |
34548 KB |
Output is correct |
39 |
Correct |
152 ms |
33764 KB |
Output is correct |
40 |
Correct |
154 ms |
34504 KB |
Output is correct |
41 |
Correct |
154 ms |
34680 KB |
Output is correct |
42 |
Correct |
163 ms |
33684 KB |
Output is correct |
43 |
Correct |
150 ms |
33616 KB |
Output is correct |
44 |
Correct |
153 ms |
33496 KB |
Output is correct |
45 |
Correct |
147 ms |
33620 KB |
Output is correct |
46 |
Correct |
150 ms |
33740 KB |
Output is correct |
47 |
Correct |
152 ms |
33484 KB |
Output is correct |
48 |
Correct |
155 ms |
34660 KB |
Output is correct |
49 |
Correct |
155 ms |
34512 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
113 ms |
19156 KB |
Output is correct |
2 |
Correct |
111 ms |
19148 KB |
Output is correct |
3 |
Correct |
112 ms |
19164 KB |
Output is correct |
4 |
Correct |
111 ms |
19028 KB |
Output is correct |
5 |
Correct |
112 ms |
19120 KB |
Output is correct |
6 |
Correct |
112 ms |
19156 KB |
Output is correct |
7 |
Correct |
112 ms |
19152 KB |
Output is correct |
8 |
Correct |
112 ms |
19144 KB |
Output is correct |
9 |
Correct |
112 ms |
19024 KB |
Output is correct |
10 |
Correct |
114 ms |
19160 KB |
Output is correct |
11 |
Correct |
112 ms |
19536 KB |
Output is correct |
12 |
Correct |
112 ms |
19028 KB |
Output is correct |
13 |
Correct |
112 ms |
19028 KB |
Output is correct |
14 |
Correct |
112 ms |
19140 KB |
Output is correct |
15 |
Correct |
115 ms |
19028 KB |
Output is correct |
16 |
Correct |
112 ms |
19028 KB |
Output is correct |
17 |
Correct |
112 ms |
19160 KB |
Output is correct |
18 |
Correct |
114 ms |
19148 KB |
Output is correct |
19 |
Correct |
112 ms |
19144 KB |
Output is correct |
20 |
Correct |
111 ms |
19164 KB |
Output is correct |
21 |
Correct |
111 ms |
19144 KB |
Output is correct |
22 |
Correct |
116 ms |
19028 KB |
Output is correct |
23 |
Correct |
112 ms |
19024 KB |
Output is correct |
24 |
Correct |
111 ms |
19028 KB |
Output is correct |
25 |
Correct |
112 ms |
19144 KB |
Output is correct |
26 |
Correct |
111 ms |
19140 KB |
Output is correct |
27 |
Correct |
111 ms |
19164 KB |
Output is correct |
28 |
Correct |
112 ms |
19024 KB |
Output is correct |
29 |
Correct |
112 ms |
19156 KB |
Output is correct |
30 |
Correct |
111 ms |
19156 KB |
Output is correct |
31 |
Correct |
111 ms |
19144 KB |
Output is correct |
32 |
Correct |
113 ms |
19164 KB |
Output is correct |
33 |
Correct |
112 ms |
19024 KB |
Output is correct |
34 |
Correct |
112 ms |
19148 KB |
Output is correct |
35 |
Correct |
149 ms |
33616 KB |
Output is correct |
36 |
Correct |
157 ms |
34252 KB |
Output is correct |
37 |
Correct |
161 ms |
34676 KB |
Output is correct |
38 |
Correct |
162 ms |
34548 KB |
Output is correct |
39 |
Correct |
152 ms |
33764 KB |
Output is correct |
40 |
Correct |
154 ms |
34504 KB |
Output is correct |
41 |
Correct |
154 ms |
34680 KB |
Output is correct |
42 |
Correct |
163 ms |
33684 KB |
Output is correct |
43 |
Correct |
150 ms |
33616 KB |
Output is correct |
44 |
Correct |
153 ms |
33496 KB |
Output is correct |
45 |
Correct |
147 ms |
33620 KB |
Output is correct |
46 |
Correct |
150 ms |
33740 KB |
Output is correct |
47 |
Correct |
152 ms |
33484 KB |
Output is correct |
48 |
Correct |
155 ms |
34660 KB |
Output is correct |
49 |
Correct |
155 ms |
34512 KB |
Output is correct |
50 |
Correct |
165 ms |
36436 KB |
Output is correct |
51 |
Correct |
166 ms |
36452 KB |
Output is correct |
52 |
Correct |
164 ms |
36436 KB |
Output is correct |
53 |
Correct |
168 ms |
36528 KB |
Output is correct |
54 |
Correct |
164 ms |
36560 KB |
Output is correct |
55 |
Correct |
165 ms |
36456 KB |
Output is correct |
56 |
Correct |
175 ms |
36588 KB |
Output is correct |
57 |
Correct |
160 ms |
35444 KB |
Output is correct |
58 |
Correct |
172 ms |
36548 KB |
Output is correct |
59 |
Correct |
166 ms |
36436 KB |
Output is correct |
60 |
Correct |
162 ms |
35544 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
113 ms |
19156 KB |
Output is correct |
2 |
Correct |
111 ms |
19148 KB |
Output is correct |
3 |
Correct |
112 ms |
19164 KB |
Output is correct |
4 |
Correct |
111 ms |
19028 KB |
Output is correct |
5 |
Correct |
112 ms |
19120 KB |
Output is correct |
6 |
Correct |
112 ms |
19156 KB |
Output is correct |
7 |
Correct |
112 ms |
19152 KB |
Output is correct |
8 |
Correct |
112 ms |
19144 KB |
Output is correct |
9 |
Correct |
112 ms |
19024 KB |
Output is correct |
10 |
Correct |
114 ms |
19160 KB |
Output is correct |
11 |
Correct |
112 ms |
19536 KB |
Output is correct |
12 |
Correct |
112 ms |
19028 KB |
Output is correct |
13 |
Correct |
112 ms |
19028 KB |
Output is correct |
14 |
Correct |
112 ms |
19140 KB |
Output is correct |
15 |
Correct |
115 ms |
19028 KB |
Output is correct |
16 |
Correct |
112 ms |
19028 KB |
Output is correct |
17 |
Correct |
112 ms |
19160 KB |
Output is correct |
18 |
Correct |
114 ms |
19148 KB |
Output is correct |
19 |
Correct |
112 ms |
19144 KB |
Output is correct |
20 |
Correct |
111 ms |
19164 KB |
Output is correct |
21 |
Correct |
111 ms |
19144 KB |
Output is correct |
22 |
Correct |
116 ms |
19028 KB |
Output is correct |
23 |
Correct |
112 ms |
19024 KB |
Output is correct |
24 |
Correct |
111 ms |
19028 KB |
Output is correct |
25 |
Correct |
112 ms |
19144 KB |
Output is correct |
26 |
Correct |
111 ms |
19140 KB |
Output is correct |
27 |
Correct |
111 ms |
19164 KB |
Output is correct |
28 |
Correct |
112 ms |
19024 KB |
Output is correct |
29 |
Correct |
112 ms |
19156 KB |
Output is correct |
30 |
Correct |
111 ms |
19156 KB |
Output is correct |
31 |
Correct |
111 ms |
19144 KB |
Output is correct |
32 |
Correct |
113 ms |
19164 KB |
Output is correct |
33 |
Correct |
112 ms |
19024 KB |
Output is correct |
34 |
Correct |
112 ms |
19148 KB |
Output is correct |
35 |
Correct |
149 ms |
33616 KB |
Output is correct |
36 |
Correct |
157 ms |
34252 KB |
Output is correct |
37 |
Correct |
161 ms |
34676 KB |
Output is correct |
38 |
Correct |
162 ms |
34548 KB |
Output is correct |
39 |
Correct |
152 ms |
33764 KB |
Output is correct |
40 |
Correct |
154 ms |
34504 KB |
Output is correct |
41 |
Correct |
154 ms |
34680 KB |
Output is correct |
42 |
Correct |
163 ms |
33684 KB |
Output is correct |
43 |
Correct |
150 ms |
33616 KB |
Output is correct |
44 |
Correct |
153 ms |
33496 KB |
Output is correct |
45 |
Correct |
147 ms |
33620 KB |
Output is correct |
46 |
Correct |
150 ms |
33740 KB |
Output is correct |
47 |
Correct |
152 ms |
33484 KB |
Output is correct |
48 |
Correct |
155 ms |
34660 KB |
Output is correct |
49 |
Correct |
155 ms |
34512 KB |
Output is correct |
50 |
Correct |
165 ms |
36436 KB |
Output is correct |
51 |
Correct |
166 ms |
36452 KB |
Output is correct |
52 |
Correct |
164 ms |
36436 KB |
Output is correct |
53 |
Correct |
168 ms |
36528 KB |
Output is correct |
54 |
Correct |
164 ms |
36560 KB |
Output is correct |
55 |
Correct |
165 ms |
36456 KB |
Output is correct |
56 |
Correct |
175 ms |
36588 KB |
Output is correct |
57 |
Correct |
160 ms |
35444 KB |
Output is correct |
58 |
Correct |
172 ms |
36548 KB |
Output is correct |
59 |
Correct |
166 ms |
36436 KB |
Output is correct |
60 |
Correct |
162 ms |
35544 KB |
Output is correct |
61 |
Correct |
114 ms |
25552 KB |
Output is correct |
62 |
Correct |
113 ms |
25556 KB |
Output is correct |
63 |
Correct |
116 ms |
26060 KB |
Output is correct |
64 |
Correct |
115 ms |
25544 KB |
Output is correct |
65 |
Correct |
146 ms |
33108 KB |
Output is correct |
66 |
Correct |
136 ms |
31824 KB |
Output is correct |
67 |
Correct |
165 ms |
37200 KB |
Output is correct |
68 |
Correct |
123 ms |
27864 KB |
Output is correct |
69 |
Correct |
113 ms |
25564 KB |
Output is correct |
70 |
Correct |
116 ms |
25684 KB |
Output is correct |
71 |
Correct |
113 ms |
25424 KB |
Output is correct |