#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define _size(x) (int)x.size()
#define BIT(i, x) ((x >> i) & 1)
#define MASK(n) ((1 << n) - 1)
#define REP(i, n) for (int i = 0, _n = (n); i < _n; i++)
#define FOR(i, a, b) for (int i = a, _b = (b); i <= _b; i++)
#define FORD(i, a, b) for (int i = a, _b = (b); i >= _b; i--)
#define FORB1(i, mask) for (int i = mask; i > 0; i ^= i & - i)
#define FORB0(i, n, mask) for (int i = ((1 << n) - 1) ^ mask; i > 0; i ^= i & - i)
#define FORALL(i, a) for (auto i: a)
#define fastio ios_base::sync_with_stdio(0); cin.tie(0);
const int mod = 1e6 + 3;
vector<int> root, p, ivp;
int getroot(int u) {
return root[u] == u ? u : (root[u] = getroot(root[u]));
}
bool unite(int u, int v) {
u = getroot(u), v = getroot(v);
if (u == v) return false;
root[v] = u;
return true;
}
int _pow(int a, int x) {
if (!x) return 1;
int t = _pow(a, x / 2);
t = (1LL * t * t) % mod;
if (x % 2) t = (1LL * t * a) % mod;
return t;
}
int C(int k, int n) {
return (1LL * p[n] * ivp[k] * ivp[n - k]) % mod;
}
int main() {
fastio;
int n, k;
cin >> n >> k;
vector<int> a(n - k + 2);
FOR(i, 1, n - k + 1) cin >> a[i];
vector<int> b(n + 1, - 1);
root.resize(n + 1);
FOR(i, 1, n) root[i] = i;
// vector<int> deg(n + 1);
FOR(i, 2, n - k + 1) {
if (a[i] == a[i - 1]) {
unite(i - 1, i + k - 1);
continue;
}
if (a[i] < a[i - 1]) b[i + k - 1] = 0, b[i - 1] = 1;
else b[i + k - 1] = 1, b[i - 1] = 0;
// deg[i - 1]++;
// deg[i + k - 1]++;
}
vector<vector<int>> adj(n + 1);
vector<int> ids;
FOR(i, 1, n) {
adj[getroot(i)].push_back(i);
ids.push_back(getroot(i));
}
sort(ids.begin(), ids.end());
ids.resize(unique(ids.begin(), ids.end()) - ids.begin());
FORALL(id, ids) {
int value = - 1;
FORALL(u, adj[id]) {
if (b[u] == - 1) continue;
if (value == - 1) value = b[u];
else if (value != b[u]) {
cout << 0 << '\n';
return 0;
}
}
if (value == - 1) continue;
FORALL(u, adj[id]) b[u] = value;
}
// int cnt = 0;
// FOR(i, 1, n) if (!deg[i]) cnt++;
p.resize(n + 1);
p[0] = 1;
FOR(i, 1, n) p[i] = (1LL * p[i - 1] * i) % mod;
ivp.resize(n + 1);
ivp[n] = _pow(p[n], mod - 2);
FORD(i, n - 1, 0) ivp[i] = (1LL * ivp[i + 1] * (i + 1)) % mod;
int cnt = 0, sum = 0;
FOR(i, 1, k) if (b[i] == - 1) cnt++; else sum += b[i];
cout << C(a[1] - sum, cnt) << '\n';
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
344 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
344 KB |
Output is correct |
6 |
Correct |
0 ms |
344 KB |
Output is correct |
7 |
Correct |
1 ms |
344 KB |
Output is correct |
8 |
Correct |
1 ms |
344 KB |
Output is correct |
9 |
Correct |
1 ms |
344 KB |
Output is correct |
10 |
Correct |
0 ms |
344 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
600 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
344 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
344 KB |
Output is correct |
6 |
Correct |
0 ms |
344 KB |
Output is correct |
7 |
Correct |
1 ms |
344 KB |
Output is correct |
8 |
Correct |
1 ms |
344 KB |
Output is correct |
9 |
Correct |
1 ms |
344 KB |
Output is correct |
10 |
Correct |
0 ms |
344 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
600 KB |
Output is correct |
13 |
Correct |
1 ms |
344 KB |
Output is correct |
14 |
Correct |
1 ms |
344 KB |
Output is correct |
15 |
Correct |
1 ms |
344 KB |
Output is correct |
16 |
Correct |
0 ms |
344 KB |
Output is correct |
17 |
Correct |
1 ms |
344 KB |
Output is correct |
18 |
Correct |
0 ms |
344 KB |
Output is correct |
19 |
Correct |
0 ms |
344 KB |
Output is correct |
20 |
Correct |
0 ms |
344 KB |
Output is correct |
21 |
Correct |
1 ms |
600 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
344 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
344 KB |
Output is correct |
6 |
Correct |
0 ms |
344 KB |
Output is correct |
7 |
Correct |
1 ms |
344 KB |
Output is correct |
8 |
Correct |
1 ms |
344 KB |
Output is correct |
9 |
Correct |
1 ms |
344 KB |
Output is correct |
10 |
Correct |
0 ms |
344 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
600 KB |
Output is correct |
13 |
Correct |
1 ms |
344 KB |
Output is correct |
14 |
Correct |
1 ms |
344 KB |
Output is correct |
15 |
Correct |
1 ms |
344 KB |
Output is correct |
16 |
Correct |
0 ms |
344 KB |
Output is correct |
17 |
Correct |
1 ms |
344 KB |
Output is correct |
18 |
Correct |
0 ms |
344 KB |
Output is correct |
19 |
Correct |
0 ms |
344 KB |
Output is correct |
20 |
Correct |
0 ms |
344 KB |
Output is correct |
21 |
Correct |
1 ms |
600 KB |
Output is correct |
22 |
Correct |
1 ms |
344 KB |
Output is correct |
23 |
Correct |
1 ms |
344 KB |
Output is correct |
24 |
Correct |
1 ms |
344 KB |
Output is correct |
25 |
Correct |
1 ms |
344 KB |
Output is correct |
26 |
Correct |
0 ms |
344 KB |
Output is correct |
27 |
Correct |
1 ms |
344 KB |
Output is correct |
28 |
Correct |
1 ms |
348 KB |
Output is correct |
29 |
Correct |
1 ms |
344 KB |
Output is correct |
30 |
Correct |
0 ms |
344 KB |
Output is correct |
31 |
Correct |
1 ms |
348 KB |
Output is correct |
32 |
Correct |
1 ms |
344 KB |
Output is correct |
33 |
Correct |
0 ms |
344 KB |
Output is correct |
34 |
Correct |
1 ms |
548 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
344 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
344 KB |
Output is correct |
6 |
Correct |
0 ms |
344 KB |
Output is correct |
7 |
Correct |
1 ms |
344 KB |
Output is correct |
8 |
Correct |
1 ms |
344 KB |
Output is correct |
9 |
Correct |
1 ms |
344 KB |
Output is correct |
10 |
Correct |
0 ms |
344 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
600 KB |
Output is correct |
13 |
Correct |
1 ms |
344 KB |
Output is correct |
14 |
Correct |
1 ms |
344 KB |
Output is correct |
15 |
Correct |
1 ms |
344 KB |
Output is correct |
16 |
Correct |
0 ms |
344 KB |
Output is correct |
17 |
Correct |
1 ms |
344 KB |
Output is correct |
18 |
Correct |
0 ms |
344 KB |
Output is correct |
19 |
Correct |
0 ms |
344 KB |
Output is correct |
20 |
Correct |
0 ms |
344 KB |
Output is correct |
21 |
Correct |
1 ms |
600 KB |
Output is correct |
22 |
Correct |
1 ms |
344 KB |
Output is correct |
23 |
Correct |
1 ms |
344 KB |
Output is correct |
24 |
Correct |
1 ms |
344 KB |
Output is correct |
25 |
Correct |
1 ms |
344 KB |
Output is correct |
26 |
Correct |
0 ms |
344 KB |
Output is correct |
27 |
Correct |
1 ms |
344 KB |
Output is correct |
28 |
Correct |
1 ms |
348 KB |
Output is correct |
29 |
Correct |
1 ms |
344 KB |
Output is correct |
30 |
Correct |
0 ms |
344 KB |
Output is correct |
31 |
Correct |
1 ms |
348 KB |
Output is correct |
32 |
Correct |
1 ms |
344 KB |
Output is correct |
33 |
Correct |
0 ms |
344 KB |
Output is correct |
34 |
Correct |
1 ms |
548 KB |
Output is correct |
35 |
Correct |
100 ms |
54364 KB |
Output is correct |
36 |
Correct |
129 ms |
57784 KB |
Output is correct |
37 |
Correct |
118 ms |
56416 KB |
Output is correct |
38 |
Correct |
112 ms |
55472 KB |
Output is correct |
39 |
Correct |
99 ms |
54220 KB |
Output is correct |
40 |
Correct |
112 ms |
55488 KB |
Output is correct |
41 |
Correct |
120 ms |
56032 KB |
Output is correct |
42 |
Correct |
114 ms |
56804 KB |
Output is correct |
43 |
Correct |
106 ms |
54200 KB |
Output is correct |
44 |
Correct |
88 ms |
53416 KB |
Output is correct |
45 |
Correct |
91 ms |
53408 KB |
Output is correct |
46 |
Correct |
87 ms |
53416 KB |
Output is correct |
47 |
Correct |
91 ms |
55340 KB |
Output is correct |
48 |
Correct |
104 ms |
55224 KB |
Output is correct |
49 |
Correct |
107 ms |
55480 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
344 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
344 KB |
Output is correct |
6 |
Correct |
0 ms |
344 KB |
Output is correct |
7 |
Correct |
1 ms |
344 KB |
Output is correct |
8 |
Correct |
1 ms |
344 KB |
Output is correct |
9 |
Correct |
1 ms |
344 KB |
Output is correct |
10 |
Correct |
0 ms |
344 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
600 KB |
Output is correct |
13 |
Correct |
1 ms |
344 KB |
Output is correct |
14 |
Correct |
1 ms |
344 KB |
Output is correct |
15 |
Correct |
1 ms |
344 KB |
Output is correct |
16 |
Correct |
0 ms |
344 KB |
Output is correct |
17 |
Correct |
1 ms |
344 KB |
Output is correct |
18 |
Correct |
0 ms |
344 KB |
Output is correct |
19 |
Correct |
0 ms |
344 KB |
Output is correct |
20 |
Correct |
0 ms |
344 KB |
Output is correct |
21 |
Correct |
1 ms |
600 KB |
Output is correct |
22 |
Correct |
1 ms |
344 KB |
Output is correct |
23 |
Correct |
1 ms |
344 KB |
Output is correct |
24 |
Correct |
1 ms |
344 KB |
Output is correct |
25 |
Correct |
1 ms |
344 KB |
Output is correct |
26 |
Correct |
0 ms |
344 KB |
Output is correct |
27 |
Correct |
1 ms |
344 KB |
Output is correct |
28 |
Correct |
1 ms |
348 KB |
Output is correct |
29 |
Correct |
1 ms |
344 KB |
Output is correct |
30 |
Correct |
0 ms |
344 KB |
Output is correct |
31 |
Correct |
1 ms |
348 KB |
Output is correct |
32 |
Correct |
1 ms |
344 KB |
Output is correct |
33 |
Correct |
0 ms |
344 KB |
Output is correct |
34 |
Correct |
1 ms |
548 KB |
Output is correct |
35 |
Correct |
100 ms |
54364 KB |
Output is correct |
36 |
Correct |
129 ms |
57784 KB |
Output is correct |
37 |
Correct |
118 ms |
56416 KB |
Output is correct |
38 |
Correct |
112 ms |
55472 KB |
Output is correct |
39 |
Correct |
99 ms |
54220 KB |
Output is correct |
40 |
Correct |
112 ms |
55488 KB |
Output is correct |
41 |
Correct |
120 ms |
56032 KB |
Output is correct |
42 |
Correct |
114 ms |
56804 KB |
Output is correct |
43 |
Correct |
106 ms |
54200 KB |
Output is correct |
44 |
Correct |
88 ms |
53416 KB |
Output is correct |
45 |
Correct |
91 ms |
53408 KB |
Output is correct |
46 |
Correct |
87 ms |
53416 KB |
Output is correct |
47 |
Correct |
91 ms |
55340 KB |
Output is correct |
48 |
Correct |
104 ms |
55224 KB |
Output is correct |
49 |
Correct |
107 ms |
55480 KB |
Output is correct |
50 |
Correct |
125 ms |
58296 KB |
Output is correct |
51 |
Correct |
120 ms |
58192 KB |
Output is correct |
52 |
Correct |
127 ms |
58448 KB |
Output is correct |
53 |
Correct |
168 ms |
61116 KB |
Output is correct |
54 |
Correct |
128 ms |
58552 KB |
Output is correct |
55 |
Correct |
123 ms |
58196 KB |
Output is correct |
56 |
Correct |
125 ms |
58296 KB |
Output is correct |
57 |
Correct |
151 ms |
59176 KB |
Output is correct |
58 |
Correct |
123 ms |
58248 KB |
Output is correct |
59 |
Correct |
139 ms |
58980 KB |
Output is correct |
60 |
Correct |
155 ms |
58624 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
344 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
344 KB |
Output is correct |
6 |
Correct |
0 ms |
344 KB |
Output is correct |
7 |
Correct |
1 ms |
344 KB |
Output is correct |
8 |
Correct |
1 ms |
344 KB |
Output is correct |
9 |
Correct |
1 ms |
344 KB |
Output is correct |
10 |
Correct |
0 ms |
344 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
600 KB |
Output is correct |
13 |
Correct |
1 ms |
344 KB |
Output is correct |
14 |
Correct |
1 ms |
344 KB |
Output is correct |
15 |
Correct |
1 ms |
344 KB |
Output is correct |
16 |
Correct |
0 ms |
344 KB |
Output is correct |
17 |
Correct |
1 ms |
344 KB |
Output is correct |
18 |
Correct |
0 ms |
344 KB |
Output is correct |
19 |
Correct |
0 ms |
344 KB |
Output is correct |
20 |
Correct |
0 ms |
344 KB |
Output is correct |
21 |
Correct |
1 ms |
600 KB |
Output is correct |
22 |
Correct |
1 ms |
344 KB |
Output is correct |
23 |
Correct |
1 ms |
344 KB |
Output is correct |
24 |
Correct |
1 ms |
344 KB |
Output is correct |
25 |
Correct |
1 ms |
344 KB |
Output is correct |
26 |
Correct |
0 ms |
344 KB |
Output is correct |
27 |
Correct |
1 ms |
344 KB |
Output is correct |
28 |
Correct |
1 ms |
348 KB |
Output is correct |
29 |
Correct |
1 ms |
344 KB |
Output is correct |
30 |
Correct |
0 ms |
344 KB |
Output is correct |
31 |
Correct |
1 ms |
348 KB |
Output is correct |
32 |
Correct |
1 ms |
344 KB |
Output is correct |
33 |
Correct |
0 ms |
344 KB |
Output is correct |
34 |
Correct |
1 ms |
548 KB |
Output is correct |
35 |
Correct |
100 ms |
54364 KB |
Output is correct |
36 |
Correct |
129 ms |
57784 KB |
Output is correct |
37 |
Correct |
118 ms |
56416 KB |
Output is correct |
38 |
Correct |
112 ms |
55472 KB |
Output is correct |
39 |
Correct |
99 ms |
54220 KB |
Output is correct |
40 |
Correct |
112 ms |
55488 KB |
Output is correct |
41 |
Correct |
120 ms |
56032 KB |
Output is correct |
42 |
Correct |
114 ms |
56804 KB |
Output is correct |
43 |
Correct |
106 ms |
54200 KB |
Output is correct |
44 |
Correct |
88 ms |
53416 KB |
Output is correct |
45 |
Correct |
91 ms |
53408 KB |
Output is correct |
46 |
Correct |
87 ms |
53416 KB |
Output is correct |
47 |
Correct |
91 ms |
55340 KB |
Output is correct |
48 |
Correct |
104 ms |
55224 KB |
Output is correct |
49 |
Correct |
107 ms |
55480 KB |
Output is correct |
50 |
Correct |
125 ms |
58296 KB |
Output is correct |
51 |
Correct |
120 ms |
58192 KB |
Output is correct |
52 |
Correct |
127 ms |
58448 KB |
Output is correct |
53 |
Correct |
168 ms |
61116 KB |
Output is correct |
54 |
Correct |
128 ms |
58552 KB |
Output is correct |
55 |
Correct |
123 ms |
58196 KB |
Output is correct |
56 |
Correct |
125 ms |
58296 KB |
Output is correct |
57 |
Correct |
151 ms |
59176 KB |
Output is correct |
58 |
Correct |
123 ms |
58248 KB |
Output is correct |
59 |
Correct |
139 ms |
58980 KB |
Output is correct |
60 |
Correct |
155 ms |
58624 KB |
Output is correct |
61 |
Correct |
83 ms |
74680 KB |
Output is correct |
62 |
Correct |
83 ms |
74680 KB |
Output is correct |
63 |
Correct |
139 ms |
74704 KB |
Output is correct |
64 |
Correct |
83 ms |
74680 KB |
Output is correct |
65 |
Correct |
151 ms |
65208 KB |
Output is correct |
66 |
Correct |
128 ms |
69724 KB |
Output is correct |
67 |
Correct |
183 ms |
64896 KB |
Output is correct |
68 |
Correct |
144 ms |
72640 KB |
Output is correct |
69 |
Correct |
81 ms |
74676 KB |
Output is correct |
70 |
Correct |
84 ms |
74700 KB |
Output is correct |
71 |
Correct |
82 ms |
74776 KB |
Output is correct |