#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb emplace_back
#define pf emplace_front
#define fi first
#define se second
#define T pair<int,int>
#define all(val) val.begin(), val.end()
#define SZ(val) (int)val.size()
#define db(val) "[" #val " = " << (val) << "] "
const int maxn = 1e6 + 4;
const int N = 16;
const int mod = 1000003;
const int INF = 1e9;
void coding() {
if (fopen("inputf.in", "r")) {
freopen("inputf.in", "r", stdin);
freopen("outputf.out", "w", stdout);
freopen("log.out", "w", stderr);
}
if (fopen(".INP", "r")) {
freopen(".INP", "r", stdin);
freopen(".OUT", "w", stdout);
}
}
int n, k, s[maxn], f[maxn], vis[maxn];
vector<pair<int,int>> adj[maxn];
void addedge(int u, int v, int w) {
// clog << u << ' ' << v << ' ' << w << endl;
adj[u].pb(v, w);
adj[v].pb(u, w);
}
void dfs(int u) {
vis[u] = 1;
for (auto it : adj[u]) if (!vis[it.fi]) {
int v, w; tie(v, w) = it;
if (f[v] != -1 && (f[u] ^ w) != f[v]) {
cout << 0;
exit(0);
}
f[v] = f[u] ^ w;
dfs(v);
}
}
int mul(int a, int b) {
return 1LL * a * b % mod;
}
int Pow(int a, int b) {
if (b == 0) return 1;
int t = Pow(a, b / 2);
t = mul(t, t);
if (b & 1) t = mul(t, a);
return t;
}
signed main()
{
ios::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
coding();
cin >> n >> k;
memset(f, -1, sizeof f);
for (int i = 1; i <= n - k + 1; i++)
cin >> s[i];
for (int i = 1; i <= n - k; i++) {
if (s[i + 1] - s[i] < -1 || s[i + 1] - s[i] > 1) return cout << 0, 0;
if (s[i + 1] - s[i] == -1) f[i] = 1, f[i + k] = 0, addedge(i, i + k, 1);
if (s[i + 1] - s[i] == 0) addedge(i, i + k, 0);
if (s[i + 1] - s[i] == 1) f[i] = 0, f[i + k] = 1, addedge(i, i + k, 1);
}
int cnt = k;
for (int i = 1; i <= k; i++) {
int root = 0;
for (int u = i; u <= n; u += k)
if (f[u] != -1)
root = u;
// clog << i << ' ' << root << endl;
if (!root) continue;
dfs(root);
if (f[i]) s[1]--;
cnt--;
}
// C(cnt, s[1])
int res = 1;
for (int i = 1; i <= s[1]; i++)
res = mul(res, Pow(i, mod - 2));
for (int i = cnt - s[1] + 1; i <= cnt; i++)
res = mul(res, i);
cout << res;
}
Compilation message
Main.cpp: In function 'void coding()':
Main.cpp:21:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
21 | freopen("inputf.in", "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:22:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
22 | freopen("outputf.out", "w", stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:23:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
23 | freopen("log.out", "w", stderr);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:26:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
26 | freopen(".INP", "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~
Main.cpp:27:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
27 | freopen(".OUT", "w", stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
31320 KB |
Output is correct |
2 |
Correct |
6 ms |
31324 KB |
Output is correct |
3 |
Correct |
6 ms |
31324 KB |
Output is correct |
4 |
Correct |
7 ms |
31404 KB |
Output is correct |
5 |
Correct |
6 ms |
31320 KB |
Output is correct |
6 |
Correct |
6 ms |
31320 KB |
Output is correct |
7 |
Correct |
6 ms |
31576 KB |
Output is correct |
8 |
Correct |
6 ms |
31324 KB |
Output is correct |
9 |
Correct |
7 ms |
31352 KB |
Output is correct |
10 |
Correct |
6 ms |
31324 KB |
Output is correct |
11 |
Correct |
6 ms |
31340 KB |
Output is correct |
12 |
Correct |
6 ms |
31324 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
31320 KB |
Output is correct |
2 |
Correct |
6 ms |
31324 KB |
Output is correct |
3 |
Correct |
6 ms |
31324 KB |
Output is correct |
4 |
Correct |
7 ms |
31404 KB |
Output is correct |
5 |
Correct |
6 ms |
31320 KB |
Output is correct |
6 |
Correct |
6 ms |
31320 KB |
Output is correct |
7 |
Correct |
6 ms |
31576 KB |
Output is correct |
8 |
Correct |
6 ms |
31324 KB |
Output is correct |
9 |
Correct |
7 ms |
31352 KB |
Output is correct |
10 |
Correct |
6 ms |
31324 KB |
Output is correct |
11 |
Correct |
6 ms |
31340 KB |
Output is correct |
12 |
Correct |
6 ms |
31324 KB |
Output is correct |
13 |
Correct |
6 ms |
31324 KB |
Output is correct |
14 |
Correct |
6 ms |
31324 KB |
Output is correct |
15 |
Correct |
8 ms |
31324 KB |
Output is correct |
16 |
Correct |
6 ms |
31324 KB |
Output is correct |
17 |
Correct |
6 ms |
31324 KB |
Output is correct |
18 |
Correct |
6 ms |
31404 KB |
Output is correct |
19 |
Correct |
6 ms |
31320 KB |
Output is correct |
20 |
Correct |
6 ms |
31324 KB |
Output is correct |
21 |
Correct |
7 ms |
31572 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
31320 KB |
Output is correct |
2 |
Correct |
6 ms |
31324 KB |
Output is correct |
3 |
Correct |
6 ms |
31324 KB |
Output is correct |
4 |
Correct |
7 ms |
31404 KB |
Output is correct |
5 |
Correct |
6 ms |
31320 KB |
Output is correct |
6 |
Correct |
6 ms |
31320 KB |
Output is correct |
7 |
Correct |
6 ms |
31576 KB |
Output is correct |
8 |
Correct |
6 ms |
31324 KB |
Output is correct |
9 |
Correct |
7 ms |
31352 KB |
Output is correct |
10 |
Correct |
6 ms |
31324 KB |
Output is correct |
11 |
Correct |
6 ms |
31340 KB |
Output is correct |
12 |
Correct |
6 ms |
31324 KB |
Output is correct |
13 |
Correct |
6 ms |
31324 KB |
Output is correct |
14 |
Correct |
6 ms |
31324 KB |
Output is correct |
15 |
Correct |
8 ms |
31324 KB |
Output is correct |
16 |
Correct |
6 ms |
31324 KB |
Output is correct |
17 |
Correct |
6 ms |
31324 KB |
Output is correct |
18 |
Correct |
6 ms |
31404 KB |
Output is correct |
19 |
Correct |
6 ms |
31320 KB |
Output is correct |
20 |
Correct |
6 ms |
31324 KB |
Output is correct |
21 |
Correct |
7 ms |
31572 KB |
Output is correct |
22 |
Correct |
7 ms |
31324 KB |
Output is correct |
23 |
Correct |
6 ms |
31428 KB |
Output is correct |
24 |
Correct |
7 ms |
31324 KB |
Output is correct |
25 |
Correct |
6 ms |
31324 KB |
Output is correct |
26 |
Correct |
7 ms |
31576 KB |
Output is correct |
27 |
Correct |
7 ms |
31324 KB |
Output is correct |
28 |
Correct |
6 ms |
31324 KB |
Output is correct |
29 |
Correct |
6 ms |
31324 KB |
Output is correct |
30 |
Correct |
6 ms |
31324 KB |
Output is correct |
31 |
Correct |
6 ms |
31324 KB |
Output is correct |
32 |
Correct |
7 ms |
31412 KB |
Output is correct |
33 |
Correct |
7 ms |
31324 KB |
Output is correct |
34 |
Correct |
7 ms |
31324 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
31320 KB |
Output is correct |
2 |
Correct |
6 ms |
31324 KB |
Output is correct |
3 |
Correct |
6 ms |
31324 KB |
Output is correct |
4 |
Correct |
7 ms |
31404 KB |
Output is correct |
5 |
Correct |
6 ms |
31320 KB |
Output is correct |
6 |
Correct |
6 ms |
31320 KB |
Output is correct |
7 |
Correct |
6 ms |
31576 KB |
Output is correct |
8 |
Correct |
6 ms |
31324 KB |
Output is correct |
9 |
Correct |
7 ms |
31352 KB |
Output is correct |
10 |
Correct |
6 ms |
31324 KB |
Output is correct |
11 |
Correct |
6 ms |
31340 KB |
Output is correct |
12 |
Correct |
6 ms |
31324 KB |
Output is correct |
13 |
Correct |
6 ms |
31324 KB |
Output is correct |
14 |
Correct |
6 ms |
31324 KB |
Output is correct |
15 |
Correct |
8 ms |
31324 KB |
Output is correct |
16 |
Correct |
6 ms |
31324 KB |
Output is correct |
17 |
Correct |
6 ms |
31324 KB |
Output is correct |
18 |
Correct |
6 ms |
31404 KB |
Output is correct |
19 |
Correct |
6 ms |
31320 KB |
Output is correct |
20 |
Correct |
6 ms |
31324 KB |
Output is correct |
21 |
Correct |
7 ms |
31572 KB |
Output is correct |
22 |
Correct |
7 ms |
31324 KB |
Output is correct |
23 |
Correct |
6 ms |
31428 KB |
Output is correct |
24 |
Correct |
7 ms |
31324 KB |
Output is correct |
25 |
Correct |
6 ms |
31324 KB |
Output is correct |
26 |
Correct |
7 ms |
31576 KB |
Output is correct |
27 |
Correct |
7 ms |
31324 KB |
Output is correct |
28 |
Correct |
6 ms |
31324 KB |
Output is correct |
29 |
Correct |
6 ms |
31324 KB |
Output is correct |
30 |
Correct |
6 ms |
31324 KB |
Output is correct |
31 |
Correct |
6 ms |
31324 KB |
Output is correct |
32 |
Correct |
7 ms |
31412 KB |
Output is correct |
33 |
Correct |
7 ms |
31324 KB |
Output is correct |
34 |
Correct |
7 ms |
31324 KB |
Output is correct |
35 |
Correct |
108 ms |
66672 KB |
Output is correct |
36 |
Correct |
156 ms |
71852 KB |
Output is correct |
37 |
Correct |
141 ms |
72256 KB |
Output is correct |
38 |
Correct |
128 ms |
72380 KB |
Output is correct |
39 |
Correct |
108 ms |
66644 KB |
Output is correct |
40 |
Correct |
112 ms |
67760 KB |
Output is correct |
41 |
Correct |
149 ms |
72252 KB |
Output is correct |
42 |
Correct |
127 ms |
72340 KB |
Output is correct |
43 |
Correct |
116 ms |
71508 KB |
Output is correct |
44 |
Correct |
109 ms |
66640 KB |
Output is correct |
45 |
Correct |
151 ms |
115796 KB |
Output is correct |
46 |
Correct |
108 ms |
66720 KB |
Output is correct |
47 |
Correct |
107 ms |
66640 KB |
Output is correct |
48 |
Correct |
113 ms |
67668 KB |
Output is correct |
49 |
Correct |
116 ms |
72096 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
31320 KB |
Output is correct |
2 |
Correct |
6 ms |
31324 KB |
Output is correct |
3 |
Correct |
6 ms |
31324 KB |
Output is correct |
4 |
Correct |
7 ms |
31404 KB |
Output is correct |
5 |
Correct |
6 ms |
31320 KB |
Output is correct |
6 |
Correct |
6 ms |
31320 KB |
Output is correct |
7 |
Correct |
6 ms |
31576 KB |
Output is correct |
8 |
Correct |
6 ms |
31324 KB |
Output is correct |
9 |
Correct |
7 ms |
31352 KB |
Output is correct |
10 |
Correct |
6 ms |
31324 KB |
Output is correct |
11 |
Correct |
6 ms |
31340 KB |
Output is correct |
12 |
Correct |
6 ms |
31324 KB |
Output is correct |
13 |
Correct |
6 ms |
31324 KB |
Output is correct |
14 |
Correct |
6 ms |
31324 KB |
Output is correct |
15 |
Correct |
8 ms |
31324 KB |
Output is correct |
16 |
Correct |
6 ms |
31324 KB |
Output is correct |
17 |
Correct |
6 ms |
31324 KB |
Output is correct |
18 |
Correct |
6 ms |
31404 KB |
Output is correct |
19 |
Correct |
6 ms |
31320 KB |
Output is correct |
20 |
Correct |
6 ms |
31324 KB |
Output is correct |
21 |
Correct |
7 ms |
31572 KB |
Output is correct |
22 |
Correct |
7 ms |
31324 KB |
Output is correct |
23 |
Correct |
6 ms |
31428 KB |
Output is correct |
24 |
Correct |
7 ms |
31324 KB |
Output is correct |
25 |
Correct |
6 ms |
31324 KB |
Output is correct |
26 |
Correct |
7 ms |
31576 KB |
Output is correct |
27 |
Correct |
7 ms |
31324 KB |
Output is correct |
28 |
Correct |
6 ms |
31324 KB |
Output is correct |
29 |
Correct |
6 ms |
31324 KB |
Output is correct |
30 |
Correct |
6 ms |
31324 KB |
Output is correct |
31 |
Correct |
6 ms |
31324 KB |
Output is correct |
32 |
Correct |
7 ms |
31412 KB |
Output is correct |
33 |
Correct |
7 ms |
31324 KB |
Output is correct |
34 |
Correct |
7 ms |
31324 KB |
Output is correct |
35 |
Correct |
108 ms |
66672 KB |
Output is correct |
36 |
Correct |
156 ms |
71852 KB |
Output is correct |
37 |
Correct |
141 ms |
72256 KB |
Output is correct |
38 |
Correct |
128 ms |
72380 KB |
Output is correct |
39 |
Correct |
108 ms |
66644 KB |
Output is correct |
40 |
Correct |
112 ms |
67760 KB |
Output is correct |
41 |
Correct |
149 ms |
72252 KB |
Output is correct |
42 |
Correct |
127 ms |
72340 KB |
Output is correct |
43 |
Correct |
116 ms |
71508 KB |
Output is correct |
44 |
Correct |
109 ms |
66640 KB |
Output is correct |
45 |
Correct |
151 ms |
115796 KB |
Output is correct |
46 |
Correct |
108 ms |
66720 KB |
Output is correct |
47 |
Correct |
107 ms |
66640 KB |
Output is correct |
48 |
Correct |
113 ms |
67668 KB |
Output is correct |
49 |
Correct |
116 ms |
72096 KB |
Output is correct |
50 |
Correct |
123 ms |
69632 KB |
Output is correct |
51 |
Correct |
128 ms |
69716 KB |
Output is correct |
52 |
Correct |
140 ms |
71840 KB |
Output is correct |
53 |
Correct |
189 ms |
71764 KB |
Output is correct |
54 |
Correct |
139 ms |
71768 KB |
Output is correct |
55 |
Correct |
126 ms |
71760 KB |
Output is correct |
56 |
Correct |
133 ms |
71844 KB |
Output is correct |
57 |
Correct |
175 ms |
70804 KB |
Output is correct |
58 |
Correct |
123 ms |
69744 KB |
Output is correct |
59 |
Correct |
158 ms |
71844 KB |
Output is correct |
60 |
Correct |
173 ms |
70744 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
31320 KB |
Output is correct |
2 |
Correct |
6 ms |
31324 KB |
Output is correct |
3 |
Correct |
6 ms |
31324 KB |
Output is correct |
4 |
Correct |
7 ms |
31404 KB |
Output is correct |
5 |
Correct |
6 ms |
31320 KB |
Output is correct |
6 |
Correct |
6 ms |
31320 KB |
Output is correct |
7 |
Correct |
6 ms |
31576 KB |
Output is correct |
8 |
Correct |
6 ms |
31324 KB |
Output is correct |
9 |
Correct |
7 ms |
31352 KB |
Output is correct |
10 |
Correct |
6 ms |
31324 KB |
Output is correct |
11 |
Correct |
6 ms |
31340 KB |
Output is correct |
12 |
Correct |
6 ms |
31324 KB |
Output is correct |
13 |
Correct |
6 ms |
31324 KB |
Output is correct |
14 |
Correct |
6 ms |
31324 KB |
Output is correct |
15 |
Correct |
8 ms |
31324 KB |
Output is correct |
16 |
Correct |
6 ms |
31324 KB |
Output is correct |
17 |
Correct |
6 ms |
31324 KB |
Output is correct |
18 |
Correct |
6 ms |
31404 KB |
Output is correct |
19 |
Correct |
6 ms |
31320 KB |
Output is correct |
20 |
Correct |
6 ms |
31324 KB |
Output is correct |
21 |
Correct |
7 ms |
31572 KB |
Output is correct |
22 |
Correct |
7 ms |
31324 KB |
Output is correct |
23 |
Correct |
6 ms |
31428 KB |
Output is correct |
24 |
Correct |
7 ms |
31324 KB |
Output is correct |
25 |
Correct |
6 ms |
31324 KB |
Output is correct |
26 |
Correct |
7 ms |
31576 KB |
Output is correct |
27 |
Correct |
7 ms |
31324 KB |
Output is correct |
28 |
Correct |
6 ms |
31324 KB |
Output is correct |
29 |
Correct |
6 ms |
31324 KB |
Output is correct |
30 |
Correct |
6 ms |
31324 KB |
Output is correct |
31 |
Correct |
6 ms |
31324 KB |
Output is correct |
32 |
Correct |
7 ms |
31412 KB |
Output is correct |
33 |
Correct |
7 ms |
31324 KB |
Output is correct |
34 |
Correct |
7 ms |
31324 KB |
Output is correct |
35 |
Correct |
108 ms |
66672 KB |
Output is correct |
36 |
Correct |
156 ms |
71852 KB |
Output is correct |
37 |
Correct |
141 ms |
72256 KB |
Output is correct |
38 |
Correct |
128 ms |
72380 KB |
Output is correct |
39 |
Correct |
108 ms |
66644 KB |
Output is correct |
40 |
Correct |
112 ms |
67760 KB |
Output is correct |
41 |
Correct |
149 ms |
72252 KB |
Output is correct |
42 |
Correct |
127 ms |
72340 KB |
Output is correct |
43 |
Correct |
116 ms |
71508 KB |
Output is correct |
44 |
Correct |
109 ms |
66640 KB |
Output is correct |
45 |
Correct |
151 ms |
115796 KB |
Output is correct |
46 |
Correct |
108 ms |
66720 KB |
Output is correct |
47 |
Correct |
107 ms |
66640 KB |
Output is correct |
48 |
Correct |
113 ms |
67668 KB |
Output is correct |
49 |
Correct |
116 ms |
72096 KB |
Output is correct |
50 |
Correct |
123 ms |
69632 KB |
Output is correct |
51 |
Correct |
128 ms |
69716 KB |
Output is correct |
52 |
Correct |
140 ms |
71840 KB |
Output is correct |
53 |
Correct |
189 ms |
71764 KB |
Output is correct |
54 |
Correct |
139 ms |
71768 KB |
Output is correct |
55 |
Correct |
126 ms |
71760 KB |
Output is correct |
56 |
Correct |
133 ms |
71844 KB |
Output is correct |
57 |
Correct |
175 ms |
70804 KB |
Output is correct |
58 |
Correct |
123 ms |
69744 KB |
Output is correct |
59 |
Correct |
158 ms |
71844 KB |
Output is correct |
60 |
Correct |
173 ms |
70744 KB |
Output is correct |
61 |
Correct |
67 ms |
31320 KB |
Output is correct |
62 |
Correct |
53 ms |
31320 KB |
Output is correct |
63 |
Correct |
111 ms |
31396 KB |
Output is correct |
64 |
Correct |
73 ms |
31396 KB |
Output is correct |
65 |
Correct |
131 ms |
70044 KB |
Output is correct |
66 |
Correct |
98 ms |
57424 KB |
Output is correct |
67 |
Correct |
131 ms |
72272 KB |
Output is correct |
68 |
Correct |
20 ms |
37468 KB |
Output is correct |
69 |
Correct |
125 ms |
31396 KB |
Output is correct |
70 |
Correct |
7 ms |
31320 KB |
Output is correct |
71 |
Correct |
67 ms |
31324 KB |
Output is correct |