#include <bits/stdc++.h>
using namespace std;
#ifdef MIKU
string dbmc = "\033[1;38;2;57;197;187m", dbrs = "\033[0m";
#define debug(x...) cout << dbmc << "[" << #x << "]: ", dout(x)
void dout() { cout << dbrs << endl; }
template <typename T, typename ...U>
void dout(T t, U ...u) { cout << t << (sizeof...(u) ? ", " : ""); dout(u...); }
#else
#define debug(...) 39
#endif
#define fs first
#define sc second
#define mp make_pair
#define FOR(i, j, k) for (int i = j, Z = k; i < Z; i++)
using ll = long long;
typedef pair<int, int> pii;
const int MXN = 1000005, mod = 1000003;
int n, k;
int a[MXN], cand, lst;
ll POW(ll a, ll b) {
ll ans = 1;
for (int i = 1 << 30; i > 0; i >>= 1) {
ans = ans * ans % mod;
if (i & b) ans = ans * a % mod;
}
return ans;
}
int C(int n, int k) {
if (n < k) return 0;
ll up = 1, dn = 1;
FOR(i, 1, n + 1) up = up * i % mod;
FOR(i, 1, k + 1) dn = dn * i % mod;
FOR(i ,1, (n - k) + 1) dn = dn * i % mod;
return up * POW(dn, mod - 2) % mod;
}
int GROUP(int x) {
int y = 0, fff = 0;
for (int i = x; i + 1 < n - k + 1; i += k) {
if (a[i] == a[i + 1]) continue;
int z = (a[i] < a[i + 1] ? 1 : -1);
if (fff == 0) fff = z;
if (y == z) return 0;
y = z;
}
if (fff == 1) {
cand--;
} else if (fff == -1) {
cand--;
lst--;
}
return 1;
}
void miku() {
cin >> n >> k;
FOR(i, 0, n - k + 1) cin >> a[i];
ll ans = 1;
lst = a[0];
cand = k;
FOR(i, 1, n - k + 1) if (abs(a[i] - a[i - 1]) > 1) {
cout << 0 << '\n';
return;
}
FOR(i, 0, k) {
ans = ans * GROUP(i) % mod;
debug(cand, lst);
}
cout << ans * C(cand, lst) << '\n';
}
int32_t main() {
cin.tie(0) -> sync_with_stdio(false);
cin.exceptions(cin.failbit);
miku();
return 0;
}
Compilation message
Main.cpp: In function 'void miku()':
Main.cpp:11:20: warning: statement has no effect [-Wunused-value]
11 | #define debug(...) 39
| ^~
Main.cpp:73:9: note: in expansion of macro 'debug'
73 | debug(cand, lst);
| ^~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
596 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
344 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
596 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
344 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
344 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
344 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
1 ms |
348 KB |
Output is correct |
21 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
596 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
344 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
344 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
344 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
1 ms |
348 KB |
Output is correct |
21 |
Correct |
0 ms |
348 KB |
Output is correct |
22 |
Correct |
0 ms |
348 KB |
Output is correct |
23 |
Correct |
0 ms |
348 KB |
Output is correct |
24 |
Correct |
1 ms |
348 KB |
Output is correct |
25 |
Correct |
0 ms |
348 KB |
Output is correct |
26 |
Correct |
0 ms |
348 KB |
Output is correct |
27 |
Correct |
0 ms |
348 KB |
Output is correct |
28 |
Correct |
0 ms |
348 KB |
Output is correct |
29 |
Correct |
1 ms |
356 KB |
Output is correct |
30 |
Correct |
0 ms |
348 KB |
Output is correct |
31 |
Correct |
0 ms |
348 KB |
Output is correct |
32 |
Correct |
0 ms |
348 KB |
Output is correct |
33 |
Correct |
0 ms |
348 KB |
Output is correct |
34 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
596 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
344 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
344 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
344 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
1 ms |
348 KB |
Output is correct |
21 |
Correct |
0 ms |
348 KB |
Output is correct |
22 |
Correct |
0 ms |
348 KB |
Output is correct |
23 |
Correct |
0 ms |
348 KB |
Output is correct |
24 |
Correct |
1 ms |
348 KB |
Output is correct |
25 |
Correct |
0 ms |
348 KB |
Output is correct |
26 |
Correct |
0 ms |
348 KB |
Output is correct |
27 |
Correct |
0 ms |
348 KB |
Output is correct |
28 |
Correct |
0 ms |
348 KB |
Output is correct |
29 |
Correct |
1 ms |
356 KB |
Output is correct |
30 |
Correct |
0 ms |
348 KB |
Output is correct |
31 |
Correct |
0 ms |
348 KB |
Output is correct |
32 |
Correct |
0 ms |
348 KB |
Output is correct |
33 |
Correct |
0 ms |
348 KB |
Output is correct |
34 |
Correct |
0 ms |
348 KB |
Output is correct |
35 |
Correct |
41 ms |
4180 KB |
Output is correct |
36 |
Correct |
44 ms |
4224 KB |
Output is correct |
37 |
Correct |
44 ms |
4180 KB |
Output is correct |
38 |
Correct |
44 ms |
4484 KB |
Output is correct |
39 |
Correct |
36 ms |
4224 KB |
Output is correct |
40 |
Correct |
43 ms |
4176 KB |
Output is correct |
41 |
Correct |
44 ms |
4236 KB |
Output is correct |
42 |
Correct |
41 ms |
4156 KB |
Output is correct |
43 |
Correct |
38 ms |
4188 KB |
Output is correct |
44 |
Correct |
41 ms |
4252 KB |
Output is correct |
45 |
Correct |
36 ms |
4328 KB |
Output is correct |
46 |
Correct |
37 ms |
4180 KB |
Output is correct |
47 |
Correct |
40 ms |
4188 KB |
Output is correct |
48 |
Correct |
43 ms |
4176 KB |
Output is correct |
49 |
Correct |
44 ms |
4176 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
596 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
344 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
344 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
344 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
1 ms |
348 KB |
Output is correct |
21 |
Correct |
0 ms |
348 KB |
Output is correct |
22 |
Correct |
0 ms |
348 KB |
Output is correct |
23 |
Correct |
0 ms |
348 KB |
Output is correct |
24 |
Correct |
1 ms |
348 KB |
Output is correct |
25 |
Correct |
0 ms |
348 KB |
Output is correct |
26 |
Correct |
0 ms |
348 KB |
Output is correct |
27 |
Correct |
0 ms |
348 KB |
Output is correct |
28 |
Correct |
0 ms |
348 KB |
Output is correct |
29 |
Correct |
1 ms |
356 KB |
Output is correct |
30 |
Correct |
0 ms |
348 KB |
Output is correct |
31 |
Correct |
0 ms |
348 KB |
Output is correct |
32 |
Correct |
0 ms |
348 KB |
Output is correct |
33 |
Correct |
0 ms |
348 KB |
Output is correct |
34 |
Correct |
0 ms |
348 KB |
Output is correct |
35 |
Correct |
41 ms |
4180 KB |
Output is correct |
36 |
Correct |
44 ms |
4224 KB |
Output is correct |
37 |
Correct |
44 ms |
4180 KB |
Output is correct |
38 |
Correct |
44 ms |
4484 KB |
Output is correct |
39 |
Correct |
36 ms |
4224 KB |
Output is correct |
40 |
Correct |
43 ms |
4176 KB |
Output is correct |
41 |
Correct |
44 ms |
4236 KB |
Output is correct |
42 |
Correct |
41 ms |
4156 KB |
Output is correct |
43 |
Correct |
38 ms |
4188 KB |
Output is correct |
44 |
Correct |
41 ms |
4252 KB |
Output is correct |
45 |
Correct |
36 ms |
4328 KB |
Output is correct |
46 |
Correct |
37 ms |
4180 KB |
Output is correct |
47 |
Correct |
40 ms |
4188 KB |
Output is correct |
48 |
Correct |
43 ms |
4176 KB |
Output is correct |
49 |
Correct |
44 ms |
4176 KB |
Output is correct |
50 |
Correct |
52 ms |
4224 KB |
Output is correct |
51 |
Correct |
63 ms |
4344 KB |
Output is correct |
52 |
Correct |
53 ms |
4228 KB |
Output is correct |
53 |
Correct |
53 ms |
4176 KB |
Output is correct |
54 |
Correct |
51 ms |
4180 KB |
Output is correct |
55 |
Correct |
53 ms |
4224 KB |
Output is correct |
56 |
Correct |
52 ms |
4228 KB |
Output is correct |
57 |
Correct |
48 ms |
4432 KB |
Output is correct |
58 |
Correct |
53 ms |
4176 KB |
Output is correct |
59 |
Correct |
53 ms |
4272 KB |
Output is correct |
60 |
Correct |
48 ms |
4180 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
596 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
344 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
344 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
344 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
1 ms |
348 KB |
Output is correct |
21 |
Correct |
0 ms |
348 KB |
Output is correct |
22 |
Correct |
0 ms |
348 KB |
Output is correct |
23 |
Correct |
0 ms |
348 KB |
Output is correct |
24 |
Correct |
1 ms |
348 KB |
Output is correct |
25 |
Correct |
0 ms |
348 KB |
Output is correct |
26 |
Correct |
0 ms |
348 KB |
Output is correct |
27 |
Correct |
0 ms |
348 KB |
Output is correct |
28 |
Correct |
0 ms |
348 KB |
Output is correct |
29 |
Correct |
1 ms |
356 KB |
Output is correct |
30 |
Correct |
0 ms |
348 KB |
Output is correct |
31 |
Correct |
0 ms |
348 KB |
Output is correct |
32 |
Correct |
0 ms |
348 KB |
Output is correct |
33 |
Correct |
0 ms |
348 KB |
Output is correct |
34 |
Correct |
0 ms |
348 KB |
Output is correct |
35 |
Correct |
41 ms |
4180 KB |
Output is correct |
36 |
Correct |
44 ms |
4224 KB |
Output is correct |
37 |
Correct |
44 ms |
4180 KB |
Output is correct |
38 |
Correct |
44 ms |
4484 KB |
Output is correct |
39 |
Correct |
36 ms |
4224 KB |
Output is correct |
40 |
Correct |
43 ms |
4176 KB |
Output is correct |
41 |
Correct |
44 ms |
4236 KB |
Output is correct |
42 |
Correct |
41 ms |
4156 KB |
Output is correct |
43 |
Correct |
38 ms |
4188 KB |
Output is correct |
44 |
Correct |
41 ms |
4252 KB |
Output is correct |
45 |
Correct |
36 ms |
4328 KB |
Output is correct |
46 |
Correct |
37 ms |
4180 KB |
Output is correct |
47 |
Correct |
40 ms |
4188 KB |
Output is correct |
48 |
Correct |
43 ms |
4176 KB |
Output is correct |
49 |
Correct |
44 ms |
4176 KB |
Output is correct |
50 |
Correct |
52 ms |
4224 KB |
Output is correct |
51 |
Correct |
63 ms |
4344 KB |
Output is correct |
52 |
Correct |
53 ms |
4228 KB |
Output is correct |
53 |
Correct |
53 ms |
4176 KB |
Output is correct |
54 |
Correct |
51 ms |
4180 KB |
Output is correct |
55 |
Correct |
53 ms |
4224 KB |
Output is correct |
56 |
Correct |
52 ms |
4228 KB |
Output is correct |
57 |
Correct |
48 ms |
4432 KB |
Output is correct |
58 |
Correct |
53 ms |
4176 KB |
Output is correct |
59 |
Correct |
53 ms |
4272 KB |
Output is correct |
60 |
Correct |
48 ms |
4180 KB |
Output is correct |
61 |
Correct |
14 ms |
344 KB |
Output is correct |
62 |
Correct |
14 ms |
348 KB |
Output is correct |
63 |
Correct |
13 ms |
348 KB |
Output is correct |
64 |
Correct |
13 ms |
344 KB |
Output is correct |
65 |
Correct |
36 ms |
2652 KB |
Output is correct |
66 |
Correct |
28 ms |
2652 KB |
Output is correct |
67 |
Correct |
51 ms |
3460 KB |
Output is correct |
68 |
Correct |
17 ms |
2704 KB |
Output is correct |
69 |
Correct |
13 ms |
348 KB |
Output is correct |
70 |
Correct |
13 ms |
464 KB |
Output is correct |
71 |
Correct |
13 ms |
348 KB |
Output is correct |