#include "bits/stdc++.h"
using namespace std;
const int maxn = 1e6 + 6;
const int mod = 1e6 + 3;
int n, k;
int a[maxn], force[maxn];
bool check[maxn];
int fact[maxn], inv[maxn];
int power(int a, int b) {
if(b == 0) return 1;
int ans = power(a, b / 2);
ans = (1ll * ans * ans % mod);
if(b & 1) return 1ll * ans * a % mod;
return ans;
}
int C(int n, int k) {
if(k > n) return 0;
return 1ll * fact[n] * inv[n - k] % mod * inv[k] % mod;
}
void solve() {
cin >> n >> k;
for(int i = 1; i <= n - k + 1; ++i) {
cin >> a[i];
}
fill(force, force + n + 1, -1);
for(int i = 2, j = k + 1; i <= n - k + 1; ++i, ++j) {
if(a[i] > a[i - 1]) {
force[j] = 1, force[j - k] = 0;
}
else if(a[i] < a[i - 1]) {
force[j - k] = 1, force[j] = 0;
}
}
for(int i = n - k + 1, j = n; i > 1; --i, --j) {
if(a[i] == a[i - 1]) {
force[j] = force[j - k] = max(force[j], force[j - k]);
}
}
int cnt = 0;
for(int i = 1; i <= k; ++i) {
if(force[i] == -1) ++cnt;
else {
a[1] -= force[i];
}
}
cout << C(cnt, a[1]);
}
signed main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
fact[0] = inv[0] = 1;
for(int i = 1; i < maxn; ++i) {
fact[i] = 1ll * fact[i - 1] * i % mod;
inv[i] = power(fact[i], mod - 2);
}
solve();
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
113 ms |
12884 KB |
Output is correct |
2 |
Correct |
116 ms |
12920 KB |
Output is correct |
3 |
Correct |
115 ms |
12880 KB |
Output is correct |
4 |
Correct |
115 ms |
12884 KB |
Output is correct |
5 |
Correct |
114 ms |
12884 KB |
Output is correct |
6 |
Correct |
114 ms |
12884 KB |
Output is correct |
7 |
Correct |
114 ms |
12936 KB |
Output is correct |
8 |
Correct |
125 ms |
12884 KB |
Output is correct |
9 |
Correct |
115 ms |
12884 KB |
Output is correct |
10 |
Correct |
115 ms |
12920 KB |
Output is correct |
11 |
Correct |
113 ms |
12916 KB |
Output is correct |
12 |
Correct |
117 ms |
12884 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
113 ms |
12884 KB |
Output is correct |
2 |
Correct |
116 ms |
12920 KB |
Output is correct |
3 |
Correct |
115 ms |
12880 KB |
Output is correct |
4 |
Correct |
115 ms |
12884 KB |
Output is correct |
5 |
Correct |
114 ms |
12884 KB |
Output is correct |
6 |
Correct |
114 ms |
12884 KB |
Output is correct |
7 |
Correct |
114 ms |
12936 KB |
Output is correct |
8 |
Correct |
125 ms |
12884 KB |
Output is correct |
9 |
Correct |
115 ms |
12884 KB |
Output is correct |
10 |
Correct |
115 ms |
12920 KB |
Output is correct |
11 |
Correct |
113 ms |
12916 KB |
Output is correct |
12 |
Correct |
117 ms |
12884 KB |
Output is correct |
13 |
Correct |
114 ms |
12920 KB |
Output is correct |
14 |
Correct |
114 ms |
12884 KB |
Output is correct |
15 |
Correct |
114 ms |
12884 KB |
Output is correct |
16 |
Correct |
115 ms |
12924 KB |
Output is correct |
17 |
Correct |
115 ms |
12920 KB |
Output is correct |
18 |
Correct |
115 ms |
12924 KB |
Output is correct |
19 |
Correct |
113 ms |
12884 KB |
Output is correct |
20 |
Correct |
116 ms |
12884 KB |
Output is correct |
21 |
Correct |
113 ms |
12928 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
113 ms |
12884 KB |
Output is correct |
2 |
Correct |
116 ms |
12920 KB |
Output is correct |
3 |
Correct |
115 ms |
12880 KB |
Output is correct |
4 |
Correct |
115 ms |
12884 KB |
Output is correct |
5 |
Correct |
114 ms |
12884 KB |
Output is correct |
6 |
Correct |
114 ms |
12884 KB |
Output is correct |
7 |
Correct |
114 ms |
12936 KB |
Output is correct |
8 |
Correct |
125 ms |
12884 KB |
Output is correct |
9 |
Correct |
115 ms |
12884 KB |
Output is correct |
10 |
Correct |
115 ms |
12920 KB |
Output is correct |
11 |
Correct |
113 ms |
12916 KB |
Output is correct |
12 |
Correct |
117 ms |
12884 KB |
Output is correct |
13 |
Correct |
114 ms |
12920 KB |
Output is correct |
14 |
Correct |
114 ms |
12884 KB |
Output is correct |
15 |
Correct |
114 ms |
12884 KB |
Output is correct |
16 |
Correct |
115 ms |
12924 KB |
Output is correct |
17 |
Correct |
115 ms |
12920 KB |
Output is correct |
18 |
Correct |
115 ms |
12924 KB |
Output is correct |
19 |
Correct |
113 ms |
12884 KB |
Output is correct |
20 |
Correct |
116 ms |
12884 KB |
Output is correct |
21 |
Correct |
113 ms |
12928 KB |
Output is correct |
22 |
Correct |
115 ms |
12884 KB |
Output is correct |
23 |
Correct |
115 ms |
12936 KB |
Output is correct |
24 |
Correct |
118 ms |
12936 KB |
Output is correct |
25 |
Correct |
116 ms |
12920 KB |
Output is correct |
26 |
Correct |
114 ms |
12928 KB |
Output is correct |
27 |
Correct |
113 ms |
12884 KB |
Output is correct |
28 |
Correct |
113 ms |
12884 KB |
Output is correct |
29 |
Correct |
117 ms |
12940 KB |
Output is correct |
30 |
Correct |
114 ms |
12932 KB |
Output is correct |
31 |
Correct |
113 ms |
12884 KB |
Output is correct |
32 |
Correct |
114 ms |
12932 KB |
Output is correct |
33 |
Correct |
115 ms |
12928 KB |
Output is correct |
34 |
Correct |
114 ms |
13140 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
113 ms |
12884 KB |
Output is correct |
2 |
Correct |
116 ms |
12920 KB |
Output is correct |
3 |
Correct |
115 ms |
12880 KB |
Output is correct |
4 |
Correct |
115 ms |
12884 KB |
Output is correct |
5 |
Correct |
114 ms |
12884 KB |
Output is correct |
6 |
Correct |
114 ms |
12884 KB |
Output is correct |
7 |
Correct |
114 ms |
12936 KB |
Output is correct |
8 |
Correct |
125 ms |
12884 KB |
Output is correct |
9 |
Correct |
115 ms |
12884 KB |
Output is correct |
10 |
Correct |
115 ms |
12920 KB |
Output is correct |
11 |
Correct |
113 ms |
12916 KB |
Output is correct |
12 |
Correct |
117 ms |
12884 KB |
Output is correct |
13 |
Correct |
114 ms |
12920 KB |
Output is correct |
14 |
Correct |
114 ms |
12884 KB |
Output is correct |
15 |
Correct |
114 ms |
12884 KB |
Output is correct |
16 |
Correct |
115 ms |
12924 KB |
Output is correct |
17 |
Correct |
115 ms |
12920 KB |
Output is correct |
18 |
Correct |
115 ms |
12924 KB |
Output is correct |
19 |
Correct |
113 ms |
12884 KB |
Output is correct |
20 |
Correct |
116 ms |
12884 KB |
Output is correct |
21 |
Correct |
113 ms |
12928 KB |
Output is correct |
22 |
Correct |
115 ms |
12884 KB |
Output is correct |
23 |
Correct |
115 ms |
12936 KB |
Output is correct |
24 |
Correct |
118 ms |
12936 KB |
Output is correct |
25 |
Correct |
116 ms |
12920 KB |
Output is correct |
26 |
Correct |
114 ms |
12928 KB |
Output is correct |
27 |
Correct |
113 ms |
12884 KB |
Output is correct |
28 |
Correct |
113 ms |
12884 KB |
Output is correct |
29 |
Correct |
117 ms |
12940 KB |
Output is correct |
30 |
Correct |
114 ms |
12932 KB |
Output is correct |
31 |
Correct |
113 ms |
12884 KB |
Output is correct |
32 |
Correct |
114 ms |
12932 KB |
Output is correct |
33 |
Correct |
115 ms |
12928 KB |
Output is correct |
34 |
Correct |
114 ms |
13140 KB |
Output is correct |
35 |
Correct |
146 ms |
18828 KB |
Output is correct |
36 |
Correct |
153 ms |
19536 KB |
Output is correct |
37 |
Correct |
154 ms |
19796 KB |
Output is correct |
38 |
Correct |
151 ms |
19796 KB |
Output is correct |
39 |
Correct |
147 ms |
19024 KB |
Output is correct |
40 |
Correct |
151 ms |
19796 KB |
Output is correct |
41 |
Correct |
151 ms |
19844 KB |
Output is correct |
42 |
Correct |
150 ms |
19032 KB |
Output is correct |
43 |
Correct |
149 ms |
18808 KB |
Output is correct |
44 |
Correct |
149 ms |
19028 KB |
Output is correct |
45 |
Correct |
146 ms |
18928 KB |
Output is correct |
46 |
Correct |
149 ms |
18824 KB |
Output is correct |
47 |
Correct |
153 ms |
18824 KB |
Output is correct |
48 |
Correct |
152 ms |
19796 KB |
Output is correct |
49 |
Correct |
150 ms |
19956 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
113 ms |
12884 KB |
Output is correct |
2 |
Correct |
116 ms |
12920 KB |
Output is correct |
3 |
Correct |
115 ms |
12880 KB |
Output is correct |
4 |
Correct |
115 ms |
12884 KB |
Output is correct |
5 |
Correct |
114 ms |
12884 KB |
Output is correct |
6 |
Correct |
114 ms |
12884 KB |
Output is correct |
7 |
Correct |
114 ms |
12936 KB |
Output is correct |
8 |
Correct |
125 ms |
12884 KB |
Output is correct |
9 |
Correct |
115 ms |
12884 KB |
Output is correct |
10 |
Correct |
115 ms |
12920 KB |
Output is correct |
11 |
Correct |
113 ms |
12916 KB |
Output is correct |
12 |
Correct |
117 ms |
12884 KB |
Output is correct |
13 |
Correct |
114 ms |
12920 KB |
Output is correct |
14 |
Correct |
114 ms |
12884 KB |
Output is correct |
15 |
Correct |
114 ms |
12884 KB |
Output is correct |
16 |
Correct |
115 ms |
12924 KB |
Output is correct |
17 |
Correct |
115 ms |
12920 KB |
Output is correct |
18 |
Correct |
115 ms |
12924 KB |
Output is correct |
19 |
Correct |
113 ms |
12884 KB |
Output is correct |
20 |
Correct |
116 ms |
12884 KB |
Output is correct |
21 |
Correct |
113 ms |
12928 KB |
Output is correct |
22 |
Correct |
115 ms |
12884 KB |
Output is correct |
23 |
Correct |
115 ms |
12936 KB |
Output is correct |
24 |
Correct |
118 ms |
12936 KB |
Output is correct |
25 |
Correct |
116 ms |
12920 KB |
Output is correct |
26 |
Correct |
114 ms |
12928 KB |
Output is correct |
27 |
Correct |
113 ms |
12884 KB |
Output is correct |
28 |
Correct |
113 ms |
12884 KB |
Output is correct |
29 |
Correct |
117 ms |
12940 KB |
Output is correct |
30 |
Correct |
114 ms |
12932 KB |
Output is correct |
31 |
Correct |
113 ms |
12884 KB |
Output is correct |
32 |
Correct |
114 ms |
12932 KB |
Output is correct |
33 |
Correct |
115 ms |
12928 KB |
Output is correct |
34 |
Correct |
114 ms |
13140 KB |
Output is correct |
35 |
Correct |
146 ms |
18828 KB |
Output is correct |
36 |
Correct |
153 ms |
19536 KB |
Output is correct |
37 |
Correct |
154 ms |
19796 KB |
Output is correct |
38 |
Correct |
151 ms |
19796 KB |
Output is correct |
39 |
Correct |
147 ms |
19024 KB |
Output is correct |
40 |
Correct |
151 ms |
19796 KB |
Output is correct |
41 |
Correct |
151 ms |
19844 KB |
Output is correct |
42 |
Correct |
150 ms |
19032 KB |
Output is correct |
43 |
Correct |
149 ms |
18808 KB |
Output is correct |
44 |
Correct |
149 ms |
19028 KB |
Output is correct |
45 |
Correct |
146 ms |
18928 KB |
Output is correct |
46 |
Correct |
149 ms |
18824 KB |
Output is correct |
47 |
Correct |
153 ms |
18824 KB |
Output is correct |
48 |
Correct |
152 ms |
19796 KB |
Output is correct |
49 |
Correct |
150 ms |
19956 KB |
Output is correct |
50 |
Correct |
160 ms |
21844 KB |
Output is correct |
51 |
Correct |
159 ms |
21892 KB |
Output is correct |
52 |
Correct |
159 ms |
21888 KB |
Output is correct |
53 |
Correct |
161 ms |
21844 KB |
Output is correct |
54 |
Correct |
162 ms |
21892 KB |
Output is correct |
55 |
Correct |
161 ms |
21892 KB |
Output is correct |
56 |
Correct |
159 ms |
21928 KB |
Output is correct |
57 |
Correct |
171 ms |
20816 KB |
Output is correct |
58 |
Correct |
159 ms |
21844 KB |
Output is correct |
59 |
Correct |
160 ms |
21892 KB |
Output is correct |
60 |
Correct |
155 ms |
20864 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
113 ms |
12884 KB |
Output is correct |
2 |
Correct |
116 ms |
12920 KB |
Output is correct |
3 |
Correct |
115 ms |
12880 KB |
Output is correct |
4 |
Correct |
115 ms |
12884 KB |
Output is correct |
5 |
Correct |
114 ms |
12884 KB |
Output is correct |
6 |
Correct |
114 ms |
12884 KB |
Output is correct |
7 |
Correct |
114 ms |
12936 KB |
Output is correct |
8 |
Correct |
125 ms |
12884 KB |
Output is correct |
9 |
Correct |
115 ms |
12884 KB |
Output is correct |
10 |
Correct |
115 ms |
12920 KB |
Output is correct |
11 |
Correct |
113 ms |
12916 KB |
Output is correct |
12 |
Correct |
117 ms |
12884 KB |
Output is correct |
13 |
Correct |
114 ms |
12920 KB |
Output is correct |
14 |
Correct |
114 ms |
12884 KB |
Output is correct |
15 |
Correct |
114 ms |
12884 KB |
Output is correct |
16 |
Correct |
115 ms |
12924 KB |
Output is correct |
17 |
Correct |
115 ms |
12920 KB |
Output is correct |
18 |
Correct |
115 ms |
12924 KB |
Output is correct |
19 |
Correct |
113 ms |
12884 KB |
Output is correct |
20 |
Correct |
116 ms |
12884 KB |
Output is correct |
21 |
Correct |
113 ms |
12928 KB |
Output is correct |
22 |
Correct |
115 ms |
12884 KB |
Output is correct |
23 |
Correct |
115 ms |
12936 KB |
Output is correct |
24 |
Correct |
118 ms |
12936 KB |
Output is correct |
25 |
Correct |
116 ms |
12920 KB |
Output is correct |
26 |
Correct |
114 ms |
12928 KB |
Output is correct |
27 |
Correct |
113 ms |
12884 KB |
Output is correct |
28 |
Correct |
113 ms |
12884 KB |
Output is correct |
29 |
Correct |
117 ms |
12940 KB |
Output is correct |
30 |
Correct |
114 ms |
12932 KB |
Output is correct |
31 |
Correct |
113 ms |
12884 KB |
Output is correct |
32 |
Correct |
114 ms |
12932 KB |
Output is correct |
33 |
Correct |
115 ms |
12928 KB |
Output is correct |
34 |
Correct |
114 ms |
13140 KB |
Output is correct |
35 |
Correct |
146 ms |
18828 KB |
Output is correct |
36 |
Correct |
153 ms |
19536 KB |
Output is correct |
37 |
Correct |
154 ms |
19796 KB |
Output is correct |
38 |
Correct |
151 ms |
19796 KB |
Output is correct |
39 |
Correct |
147 ms |
19024 KB |
Output is correct |
40 |
Correct |
151 ms |
19796 KB |
Output is correct |
41 |
Correct |
151 ms |
19844 KB |
Output is correct |
42 |
Correct |
150 ms |
19032 KB |
Output is correct |
43 |
Correct |
149 ms |
18808 KB |
Output is correct |
44 |
Correct |
149 ms |
19028 KB |
Output is correct |
45 |
Correct |
146 ms |
18928 KB |
Output is correct |
46 |
Correct |
149 ms |
18824 KB |
Output is correct |
47 |
Correct |
153 ms |
18824 KB |
Output is correct |
48 |
Correct |
152 ms |
19796 KB |
Output is correct |
49 |
Correct |
150 ms |
19956 KB |
Output is correct |
50 |
Correct |
160 ms |
21844 KB |
Output is correct |
51 |
Correct |
159 ms |
21892 KB |
Output is correct |
52 |
Correct |
159 ms |
21888 KB |
Output is correct |
53 |
Correct |
161 ms |
21844 KB |
Output is correct |
54 |
Correct |
162 ms |
21892 KB |
Output is correct |
55 |
Correct |
161 ms |
21892 KB |
Output is correct |
56 |
Correct |
159 ms |
21928 KB |
Output is correct |
57 |
Correct |
171 ms |
20816 KB |
Output is correct |
58 |
Correct |
159 ms |
21844 KB |
Output is correct |
59 |
Correct |
160 ms |
21892 KB |
Output is correct |
60 |
Correct |
155 ms |
20864 KB |
Output is correct |
61 |
Correct |
114 ms |
14932 KB |
Output is correct |
62 |
Correct |
115 ms |
14932 KB |
Output is correct |
63 |
Correct |
114 ms |
14928 KB |
Output is correct |
64 |
Correct |
115 ms |
14932 KB |
Output is correct |
65 |
Correct |
134 ms |
20308 KB |
Output is correct |
66 |
Correct |
134 ms |
17236 KB |
Output is correct |
67 |
Correct |
163 ms |
22356 KB |
Output is correct |
68 |
Correct |
122 ms |
15188 KB |
Output is correct |
69 |
Correct |
114 ms |
14932 KB |
Output is correct |
70 |
Correct |
114 ms |
14980 KB |
Output is correct |
71 |
Correct |
114 ms |
14976 KB |
Output is correct |