#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#include "debug.h"
#else
#define debug(...)
#endif
#define file ""
#define mp make_pair
#define fi first
#define se second
#define all(x) x.begin(), x.end()
#define bit(x) (1LL << (x))
#define getbit(x, i) (((x) >> (i)) & 1)
#define popcount __builtin_popcountll
mt19937_64 rd(chrono::steady_clock::now().time_since_epoch().count());
int rand(int l, int r) {
return l + rd() % (r - l + 1);
}
const int N = 1e6 + 5;
const int mod = (int)1e6 + 3; // 998244353;
const int lg = 25; // lg + 1
const int oo = 1e9;
const long long ooo = 1e18;
template<class X, class Y> bool mini(X &a, Y b) {
return a > b ? (a = b, true) : false;
}
template<class X, class Y> bool maxi(X &a, Y b) {
return a < b ? (a = b, true) : false;
}
void add(int &a, int b) {
a += b;
if (a >= mod) a -= mod;
if (a < 0) a += mod;
}
int n, k;
int a[N];
int pw(int x, int y) {
int res = 1;
while (y) {
if (y & 1) res = 1LL * res * x % mod;
x = 1LL * x * x % mod;
y >>= 1;
}
return res;
}
int fac[N], inv[N];
void pre() {
int n = 1e6;
fac[0] = 1;
for (int i = 1; i <= n; ++i) fac[i] = 1LL * fac[i - 1] * i % mod;
inv[n] = pw(fac[n], mod - 2);
for (int i = n; i >= 1; --i) inv[i - 1] = 1LL * inv[i] * i % mod;
}
int nCk(int n, int k) {
if (k < 0 || k > n) return 0;
return 1LL * fac[n] * inv[k] % mod * inv[n - k] % mod;
}
int ok[N];
void process() {
pre();
cin >> n >> k;
for (int i = 1; i <= n - k + 1; ++i) cin >> a[i];
memset(ok, -1, sizeof ok);
for (int i = n - k; i >= 1; --i) {
if (abs(a[i] - a[i + 1]) > 1) {
cout << 0;
return;
}
if (a[i] == a[i + 1]) ok[i] = ok[i + k];
else if (a[i] < a[i + 1]) {
ok[i] = 0;
if (ok[i + k] == 0) {
cout << 0;
return;
}
}
else if (a[i] > a[i + 1]) {
ok[i] = 1;
if (ok[i + k] == 1) {
cout << 0;
return;
}
}
}
int cnt = 0;
for (int i = 1; i <= k; ++i) {
a[1] -= (ok[i] == 1);
cnt += (ok[i] == -1);
}
debug(cnt, a[1]);
cout << nCk(cnt, a[1]);
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
#ifdef LOCAL
freopen("input.txt", "r", stdin);
#else
// freopen(file".inp", "r", stdin);
// freopen(file".out", "w", stdout);
#endif
int tc = 1;
// cin >> tc;
while (tc--) {
process();
}
return 0;
}
/*
*/
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
11 ms |
12892 KB |
Output is correct |
2 |
Correct |
11 ms |
12764 KB |
Output is correct |
3 |
Correct |
11 ms |
12764 KB |
Output is correct |
4 |
Correct |
11 ms |
12760 KB |
Output is correct |
5 |
Correct |
11 ms |
12888 KB |
Output is correct |
6 |
Correct |
11 ms |
12892 KB |
Output is correct |
7 |
Correct |
11 ms |
12764 KB |
Output is correct |
8 |
Correct |
11 ms |
12956 KB |
Output is correct |
9 |
Correct |
12 ms |
12892 KB |
Output is correct |
10 |
Correct |
11 ms |
12892 KB |
Output is correct |
11 |
Correct |
11 ms |
12892 KB |
Output is correct |
12 |
Correct |
11 ms |
12892 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
11 ms |
12892 KB |
Output is correct |
2 |
Correct |
11 ms |
12764 KB |
Output is correct |
3 |
Correct |
11 ms |
12764 KB |
Output is correct |
4 |
Correct |
11 ms |
12760 KB |
Output is correct |
5 |
Correct |
11 ms |
12888 KB |
Output is correct |
6 |
Correct |
11 ms |
12892 KB |
Output is correct |
7 |
Correct |
11 ms |
12764 KB |
Output is correct |
8 |
Correct |
11 ms |
12956 KB |
Output is correct |
9 |
Correct |
12 ms |
12892 KB |
Output is correct |
10 |
Correct |
11 ms |
12892 KB |
Output is correct |
11 |
Correct |
11 ms |
12892 KB |
Output is correct |
12 |
Correct |
11 ms |
12892 KB |
Output is correct |
13 |
Correct |
11 ms |
12888 KB |
Output is correct |
14 |
Correct |
11 ms |
13012 KB |
Output is correct |
15 |
Correct |
11 ms |
12892 KB |
Output is correct |
16 |
Correct |
11 ms |
12776 KB |
Output is correct |
17 |
Correct |
11 ms |
12892 KB |
Output is correct |
18 |
Correct |
11 ms |
12776 KB |
Output is correct |
19 |
Correct |
11 ms |
12768 KB |
Output is correct |
20 |
Correct |
11 ms |
12888 KB |
Output is correct |
21 |
Correct |
11 ms |
12768 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
11 ms |
12892 KB |
Output is correct |
2 |
Correct |
11 ms |
12764 KB |
Output is correct |
3 |
Correct |
11 ms |
12764 KB |
Output is correct |
4 |
Correct |
11 ms |
12760 KB |
Output is correct |
5 |
Correct |
11 ms |
12888 KB |
Output is correct |
6 |
Correct |
11 ms |
12892 KB |
Output is correct |
7 |
Correct |
11 ms |
12764 KB |
Output is correct |
8 |
Correct |
11 ms |
12956 KB |
Output is correct |
9 |
Correct |
12 ms |
12892 KB |
Output is correct |
10 |
Correct |
11 ms |
12892 KB |
Output is correct |
11 |
Correct |
11 ms |
12892 KB |
Output is correct |
12 |
Correct |
11 ms |
12892 KB |
Output is correct |
13 |
Correct |
11 ms |
12888 KB |
Output is correct |
14 |
Correct |
11 ms |
13012 KB |
Output is correct |
15 |
Correct |
11 ms |
12892 KB |
Output is correct |
16 |
Correct |
11 ms |
12776 KB |
Output is correct |
17 |
Correct |
11 ms |
12892 KB |
Output is correct |
18 |
Correct |
11 ms |
12776 KB |
Output is correct |
19 |
Correct |
11 ms |
12768 KB |
Output is correct |
20 |
Correct |
11 ms |
12888 KB |
Output is correct |
21 |
Correct |
11 ms |
12768 KB |
Output is correct |
22 |
Correct |
11 ms |
12892 KB |
Output is correct |
23 |
Correct |
11 ms |
12892 KB |
Output is correct |
24 |
Correct |
11 ms |
12892 KB |
Output is correct |
25 |
Correct |
11 ms |
12892 KB |
Output is correct |
26 |
Correct |
11 ms |
12892 KB |
Output is correct |
27 |
Correct |
11 ms |
12892 KB |
Output is correct |
28 |
Correct |
11 ms |
13020 KB |
Output is correct |
29 |
Correct |
11 ms |
12892 KB |
Output is correct |
30 |
Correct |
11 ms |
12764 KB |
Output is correct |
31 |
Correct |
11 ms |
12892 KB |
Output is correct |
32 |
Correct |
11 ms |
12888 KB |
Output is correct |
33 |
Correct |
11 ms |
12892 KB |
Output is correct |
34 |
Correct |
11 ms |
12892 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
11 ms |
12892 KB |
Output is correct |
2 |
Correct |
11 ms |
12764 KB |
Output is correct |
3 |
Correct |
11 ms |
12764 KB |
Output is correct |
4 |
Correct |
11 ms |
12760 KB |
Output is correct |
5 |
Correct |
11 ms |
12888 KB |
Output is correct |
6 |
Correct |
11 ms |
12892 KB |
Output is correct |
7 |
Correct |
11 ms |
12764 KB |
Output is correct |
8 |
Correct |
11 ms |
12956 KB |
Output is correct |
9 |
Correct |
12 ms |
12892 KB |
Output is correct |
10 |
Correct |
11 ms |
12892 KB |
Output is correct |
11 |
Correct |
11 ms |
12892 KB |
Output is correct |
12 |
Correct |
11 ms |
12892 KB |
Output is correct |
13 |
Correct |
11 ms |
12888 KB |
Output is correct |
14 |
Correct |
11 ms |
13012 KB |
Output is correct |
15 |
Correct |
11 ms |
12892 KB |
Output is correct |
16 |
Correct |
11 ms |
12776 KB |
Output is correct |
17 |
Correct |
11 ms |
12892 KB |
Output is correct |
18 |
Correct |
11 ms |
12776 KB |
Output is correct |
19 |
Correct |
11 ms |
12768 KB |
Output is correct |
20 |
Correct |
11 ms |
12888 KB |
Output is correct |
21 |
Correct |
11 ms |
12768 KB |
Output is correct |
22 |
Correct |
11 ms |
12892 KB |
Output is correct |
23 |
Correct |
11 ms |
12892 KB |
Output is correct |
24 |
Correct |
11 ms |
12892 KB |
Output is correct |
25 |
Correct |
11 ms |
12892 KB |
Output is correct |
26 |
Correct |
11 ms |
12892 KB |
Output is correct |
27 |
Correct |
11 ms |
12892 KB |
Output is correct |
28 |
Correct |
11 ms |
13020 KB |
Output is correct |
29 |
Correct |
11 ms |
12892 KB |
Output is correct |
30 |
Correct |
11 ms |
12764 KB |
Output is correct |
31 |
Correct |
11 ms |
12892 KB |
Output is correct |
32 |
Correct |
11 ms |
12888 KB |
Output is correct |
33 |
Correct |
11 ms |
12892 KB |
Output is correct |
34 |
Correct |
11 ms |
12892 KB |
Output is correct |
35 |
Correct |
61 ms |
18000 KB |
Output is correct |
36 |
Correct |
54 ms |
18632 KB |
Output is correct |
37 |
Correct |
59 ms |
19024 KB |
Output is correct |
38 |
Correct |
54 ms |
19024 KB |
Output is correct |
39 |
Correct |
50 ms |
18004 KB |
Output is correct |
40 |
Correct |
54 ms |
19012 KB |
Output is correct |
41 |
Correct |
59 ms |
19024 KB |
Output is correct |
42 |
Correct |
50 ms |
17860 KB |
Output is correct |
43 |
Correct |
54 ms |
17992 KB |
Output is correct |
44 |
Correct |
50 ms |
18000 KB |
Output is correct |
45 |
Correct |
55 ms |
18004 KB |
Output is correct |
46 |
Correct |
49 ms |
18000 KB |
Output is correct |
47 |
Correct |
49 ms |
17872 KB |
Output is correct |
48 |
Correct |
60 ms |
19164 KB |
Output is correct |
49 |
Correct |
57 ms |
18772 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
11 ms |
12892 KB |
Output is correct |
2 |
Correct |
11 ms |
12764 KB |
Output is correct |
3 |
Correct |
11 ms |
12764 KB |
Output is correct |
4 |
Correct |
11 ms |
12760 KB |
Output is correct |
5 |
Correct |
11 ms |
12888 KB |
Output is correct |
6 |
Correct |
11 ms |
12892 KB |
Output is correct |
7 |
Correct |
11 ms |
12764 KB |
Output is correct |
8 |
Correct |
11 ms |
12956 KB |
Output is correct |
9 |
Correct |
12 ms |
12892 KB |
Output is correct |
10 |
Correct |
11 ms |
12892 KB |
Output is correct |
11 |
Correct |
11 ms |
12892 KB |
Output is correct |
12 |
Correct |
11 ms |
12892 KB |
Output is correct |
13 |
Correct |
11 ms |
12888 KB |
Output is correct |
14 |
Correct |
11 ms |
13012 KB |
Output is correct |
15 |
Correct |
11 ms |
12892 KB |
Output is correct |
16 |
Correct |
11 ms |
12776 KB |
Output is correct |
17 |
Correct |
11 ms |
12892 KB |
Output is correct |
18 |
Correct |
11 ms |
12776 KB |
Output is correct |
19 |
Correct |
11 ms |
12768 KB |
Output is correct |
20 |
Correct |
11 ms |
12888 KB |
Output is correct |
21 |
Correct |
11 ms |
12768 KB |
Output is correct |
22 |
Correct |
11 ms |
12892 KB |
Output is correct |
23 |
Correct |
11 ms |
12892 KB |
Output is correct |
24 |
Correct |
11 ms |
12892 KB |
Output is correct |
25 |
Correct |
11 ms |
12892 KB |
Output is correct |
26 |
Correct |
11 ms |
12892 KB |
Output is correct |
27 |
Correct |
11 ms |
12892 KB |
Output is correct |
28 |
Correct |
11 ms |
13020 KB |
Output is correct |
29 |
Correct |
11 ms |
12892 KB |
Output is correct |
30 |
Correct |
11 ms |
12764 KB |
Output is correct |
31 |
Correct |
11 ms |
12892 KB |
Output is correct |
32 |
Correct |
11 ms |
12888 KB |
Output is correct |
33 |
Correct |
11 ms |
12892 KB |
Output is correct |
34 |
Correct |
11 ms |
12892 KB |
Output is correct |
35 |
Correct |
61 ms |
18000 KB |
Output is correct |
36 |
Correct |
54 ms |
18632 KB |
Output is correct |
37 |
Correct |
59 ms |
19024 KB |
Output is correct |
38 |
Correct |
54 ms |
19024 KB |
Output is correct |
39 |
Correct |
50 ms |
18004 KB |
Output is correct |
40 |
Correct |
54 ms |
19012 KB |
Output is correct |
41 |
Correct |
59 ms |
19024 KB |
Output is correct |
42 |
Correct |
50 ms |
17860 KB |
Output is correct |
43 |
Correct |
54 ms |
17992 KB |
Output is correct |
44 |
Correct |
50 ms |
18000 KB |
Output is correct |
45 |
Correct |
55 ms |
18004 KB |
Output is correct |
46 |
Correct |
49 ms |
18000 KB |
Output is correct |
47 |
Correct |
49 ms |
17872 KB |
Output is correct |
48 |
Correct |
60 ms |
19164 KB |
Output is correct |
49 |
Correct |
57 ms |
18772 KB |
Output is correct |
50 |
Correct |
63 ms |
20820 KB |
Output is correct |
51 |
Correct |
77 ms |
20812 KB |
Output is correct |
52 |
Correct |
62 ms |
20808 KB |
Output is correct |
53 |
Correct |
78 ms |
20908 KB |
Output is correct |
54 |
Correct |
63 ms |
20816 KB |
Output is correct |
55 |
Correct |
63 ms |
20820 KB |
Output is correct |
56 |
Correct |
64 ms |
20816 KB |
Output is correct |
57 |
Correct |
59 ms |
19904 KB |
Output is correct |
58 |
Correct |
78 ms |
20944 KB |
Output is correct |
59 |
Correct |
64 ms |
20820 KB |
Output is correct |
60 |
Correct |
59 ms |
19796 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
11 ms |
12892 KB |
Output is correct |
2 |
Correct |
11 ms |
12764 KB |
Output is correct |
3 |
Correct |
11 ms |
12764 KB |
Output is correct |
4 |
Correct |
11 ms |
12760 KB |
Output is correct |
5 |
Correct |
11 ms |
12888 KB |
Output is correct |
6 |
Correct |
11 ms |
12892 KB |
Output is correct |
7 |
Correct |
11 ms |
12764 KB |
Output is correct |
8 |
Correct |
11 ms |
12956 KB |
Output is correct |
9 |
Correct |
12 ms |
12892 KB |
Output is correct |
10 |
Correct |
11 ms |
12892 KB |
Output is correct |
11 |
Correct |
11 ms |
12892 KB |
Output is correct |
12 |
Correct |
11 ms |
12892 KB |
Output is correct |
13 |
Correct |
11 ms |
12888 KB |
Output is correct |
14 |
Correct |
11 ms |
13012 KB |
Output is correct |
15 |
Correct |
11 ms |
12892 KB |
Output is correct |
16 |
Correct |
11 ms |
12776 KB |
Output is correct |
17 |
Correct |
11 ms |
12892 KB |
Output is correct |
18 |
Correct |
11 ms |
12776 KB |
Output is correct |
19 |
Correct |
11 ms |
12768 KB |
Output is correct |
20 |
Correct |
11 ms |
12888 KB |
Output is correct |
21 |
Correct |
11 ms |
12768 KB |
Output is correct |
22 |
Correct |
11 ms |
12892 KB |
Output is correct |
23 |
Correct |
11 ms |
12892 KB |
Output is correct |
24 |
Correct |
11 ms |
12892 KB |
Output is correct |
25 |
Correct |
11 ms |
12892 KB |
Output is correct |
26 |
Correct |
11 ms |
12892 KB |
Output is correct |
27 |
Correct |
11 ms |
12892 KB |
Output is correct |
28 |
Correct |
11 ms |
13020 KB |
Output is correct |
29 |
Correct |
11 ms |
12892 KB |
Output is correct |
30 |
Correct |
11 ms |
12764 KB |
Output is correct |
31 |
Correct |
11 ms |
12892 KB |
Output is correct |
32 |
Correct |
11 ms |
12888 KB |
Output is correct |
33 |
Correct |
11 ms |
12892 KB |
Output is correct |
34 |
Correct |
11 ms |
12892 KB |
Output is correct |
35 |
Correct |
61 ms |
18000 KB |
Output is correct |
36 |
Correct |
54 ms |
18632 KB |
Output is correct |
37 |
Correct |
59 ms |
19024 KB |
Output is correct |
38 |
Correct |
54 ms |
19024 KB |
Output is correct |
39 |
Correct |
50 ms |
18004 KB |
Output is correct |
40 |
Correct |
54 ms |
19012 KB |
Output is correct |
41 |
Correct |
59 ms |
19024 KB |
Output is correct |
42 |
Correct |
50 ms |
17860 KB |
Output is correct |
43 |
Correct |
54 ms |
17992 KB |
Output is correct |
44 |
Correct |
50 ms |
18000 KB |
Output is correct |
45 |
Correct |
55 ms |
18004 KB |
Output is correct |
46 |
Correct |
49 ms |
18000 KB |
Output is correct |
47 |
Correct |
49 ms |
17872 KB |
Output is correct |
48 |
Correct |
60 ms |
19164 KB |
Output is correct |
49 |
Correct |
57 ms |
18772 KB |
Output is correct |
50 |
Correct |
63 ms |
20820 KB |
Output is correct |
51 |
Correct |
77 ms |
20812 KB |
Output is correct |
52 |
Correct |
62 ms |
20808 KB |
Output is correct |
53 |
Correct |
78 ms |
20908 KB |
Output is correct |
54 |
Correct |
63 ms |
20816 KB |
Output is correct |
55 |
Correct |
63 ms |
20820 KB |
Output is correct |
56 |
Correct |
64 ms |
20816 KB |
Output is correct |
57 |
Correct |
59 ms |
19904 KB |
Output is correct |
58 |
Correct |
78 ms |
20944 KB |
Output is correct |
59 |
Correct |
64 ms |
20820 KB |
Output is correct |
60 |
Correct |
59 ms |
19796 KB |
Output is correct |
61 |
Correct |
12 ms |
12888 KB |
Output is correct |
62 |
Correct |
12 ms |
12892 KB |
Output is correct |
63 |
Correct |
12 ms |
12760 KB |
Output is correct |
64 |
Correct |
12 ms |
12892 KB |
Output is correct |
65 |
Correct |
43 ms |
18228 KB |
Output is correct |
66 |
Correct |
39 ms |
17352 KB |
Output is correct |
67 |
Correct |
62 ms |
20548 KB |
Output is correct |
68 |
Correct |
16 ms |
13400 KB |
Output is correct |
69 |
Correct |
12 ms |
12892 KB |
Output is correct |
70 |
Correct |
12 ms |
12892 KB |
Output is correct |
71 |
Correct |
12 ms |
12892 KB |
Output is correct |