#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("Rebinary.INP", "r")) {
freopen("Rebinary.INP", "r", stdin);
freopen("Rebinary.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) {
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;
if (!root) continue;
// dfs(root);
if (f[i]) s[1]--;
cnt--;
}
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("Rebinary.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("Rebinary.OUT", "w", stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
31324 KB |
Output is correct |
2 |
Correct |
6 ms |
31324 KB |
Output is correct |
3 |
Correct |
6 ms |
31324 KB |
Output is correct |
4 |
Correct |
6 ms |
31324 KB |
Output is correct |
5 |
Correct |
6 ms |
31344 KB |
Output is correct |
6 |
Correct |
6 ms |
31324 KB |
Output is correct |
7 |
Correct |
7 ms |
31324 KB |
Output is correct |
8 |
Correct |
7 ms |
31356 KB |
Output is correct |
9 |
Correct |
6 ms |
31324 KB |
Output is correct |
10 |
Correct |
6 ms |
31324 KB |
Output is correct |
11 |
Correct |
7 ms |
31324 KB |
Output is correct |
12 |
Correct |
6 ms |
31324 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
31324 KB |
Output is correct |
2 |
Correct |
6 ms |
31324 KB |
Output is correct |
3 |
Correct |
6 ms |
31324 KB |
Output is correct |
4 |
Correct |
6 ms |
31324 KB |
Output is correct |
5 |
Correct |
6 ms |
31344 KB |
Output is correct |
6 |
Correct |
6 ms |
31324 KB |
Output is correct |
7 |
Correct |
7 ms |
31324 KB |
Output is correct |
8 |
Correct |
7 ms |
31356 KB |
Output is correct |
9 |
Correct |
6 ms |
31324 KB |
Output is correct |
10 |
Correct |
6 ms |
31324 KB |
Output is correct |
11 |
Correct |
7 ms |
31324 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 |
7 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 |
31324 KB |
Output is correct |
19 |
Correct |
6 ms |
31324 KB |
Output is correct |
20 |
Correct |
6 ms |
31320 KB |
Output is correct |
21 |
Correct |
6 ms |
31480 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
31324 KB |
Output is correct |
2 |
Correct |
6 ms |
31324 KB |
Output is correct |
3 |
Correct |
6 ms |
31324 KB |
Output is correct |
4 |
Correct |
6 ms |
31324 KB |
Output is correct |
5 |
Correct |
6 ms |
31344 KB |
Output is correct |
6 |
Correct |
6 ms |
31324 KB |
Output is correct |
7 |
Correct |
7 ms |
31324 KB |
Output is correct |
8 |
Correct |
7 ms |
31356 KB |
Output is correct |
9 |
Correct |
6 ms |
31324 KB |
Output is correct |
10 |
Correct |
6 ms |
31324 KB |
Output is correct |
11 |
Correct |
7 ms |
31324 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 |
7 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 |
31324 KB |
Output is correct |
19 |
Correct |
6 ms |
31324 KB |
Output is correct |
20 |
Correct |
6 ms |
31320 KB |
Output is correct |
21 |
Correct |
6 ms |
31480 KB |
Output is correct |
22 |
Correct |
7 ms |
31324 KB |
Output is correct |
23 |
Correct |
6 ms |
31324 KB |
Output is correct |
24 |
Correct |
6 ms |
31332 KB |
Output is correct |
25 |
Correct |
6 ms |
31324 KB |
Output is correct |
26 |
Correct |
6 ms |
31324 KB |
Output is correct |
27 |
Correct |
6 ms |
31324 KB |
Output is correct |
28 |
Correct |
6 ms |
31364 KB |
Output is correct |
29 |
Correct |
6 ms |
31324 KB |
Output is correct |
30 |
Correct |
7 ms |
31364 KB |
Output is correct |
31 |
Correct |
7 ms |
31324 KB |
Output is correct |
32 |
Incorrect |
7 ms |
31452 KB |
Output isn't correct |
33 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
31324 KB |
Output is correct |
2 |
Correct |
6 ms |
31324 KB |
Output is correct |
3 |
Correct |
6 ms |
31324 KB |
Output is correct |
4 |
Correct |
6 ms |
31324 KB |
Output is correct |
5 |
Correct |
6 ms |
31344 KB |
Output is correct |
6 |
Correct |
6 ms |
31324 KB |
Output is correct |
7 |
Correct |
7 ms |
31324 KB |
Output is correct |
8 |
Correct |
7 ms |
31356 KB |
Output is correct |
9 |
Correct |
6 ms |
31324 KB |
Output is correct |
10 |
Correct |
6 ms |
31324 KB |
Output is correct |
11 |
Correct |
7 ms |
31324 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 |
7 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 |
31324 KB |
Output is correct |
19 |
Correct |
6 ms |
31324 KB |
Output is correct |
20 |
Correct |
6 ms |
31320 KB |
Output is correct |
21 |
Correct |
6 ms |
31480 KB |
Output is correct |
22 |
Correct |
7 ms |
31324 KB |
Output is correct |
23 |
Correct |
6 ms |
31324 KB |
Output is correct |
24 |
Correct |
6 ms |
31332 KB |
Output is correct |
25 |
Correct |
6 ms |
31324 KB |
Output is correct |
26 |
Correct |
6 ms |
31324 KB |
Output is correct |
27 |
Correct |
6 ms |
31324 KB |
Output is correct |
28 |
Correct |
6 ms |
31364 KB |
Output is correct |
29 |
Correct |
6 ms |
31324 KB |
Output is correct |
30 |
Correct |
7 ms |
31364 KB |
Output is correct |
31 |
Correct |
7 ms |
31324 KB |
Output is correct |
32 |
Incorrect |
7 ms |
31452 KB |
Output isn't correct |
33 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
31324 KB |
Output is correct |
2 |
Correct |
6 ms |
31324 KB |
Output is correct |
3 |
Correct |
6 ms |
31324 KB |
Output is correct |
4 |
Correct |
6 ms |
31324 KB |
Output is correct |
5 |
Correct |
6 ms |
31344 KB |
Output is correct |
6 |
Correct |
6 ms |
31324 KB |
Output is correct |
7 |
Correct |
7 ms |
31324 KB |
Output is correct |
8 |
Correct |
7 ms |
31356 KB |
Output is correct |
9 |
Correct |
6 ms |
31324 KB |
Output is correct |
10 |
Correct |
6 ms |
31324 KB |
Output is correct |
11 |
Correct |
7 ms |
31324 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 |
7 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 |
31324 KB |
Output is correct |
19 |
Correct |
6 ms |
31324 KB |
Output is correct |
20 |
Correct |
6 ms |
31320 KB |
Output is correct |
21 |
Correct |
6 ms |
31480 KB |
Output is correct |
22 |
Correct |
7 ms |
31324 KB |
Output is correct |
23 |
Correct |
6 ms |
31324 KB |
Output is correct |
24 |
Correct |
6 ms |
31332 KB |
Output is correct |
25 |
Correct |
6 ms |
31324 KB |
Output is correct |
26 |
Correct |
6 ms |
31324 KB |
Output is correct |
27 |
Correct |
6 ms |
31324 KB |
Output is correct |
28 |
Correct |
6 ms |
31364 KB |
Output is correct |
29 |
Correct |
6 ms |
31324 KB |
Output is correct |
30 |
Correct |
7 ms |
31364 KB |
Output is correct |
31 |
Correct |
7 ms |
31324 KB |
Output is correct |
32 |
Incorrect |
7 ms |
31452 KB |
Output isn't correct |
33 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
31324 KB |
Output is correct |
2 |
Correct |
6 ms |
31324 KB |
Output is correct |
3 |
Correct |
6 ms |
31324 KB |
Output is correct |
4 |
Correct |
6 ms |
31324 KB |
Output is correct |
5 |
Correct |
6 ms |
31344 KB |
Output is correct |
6 |
Correct |
6 ms |
31324 KB |
Output is correct |
7 |
Correct |
7 ms |
31324 KB |
Output is correct |
8 |
Correct |
7 ms |
31356 KB |
Output is correct |
9 |
Correct |
6 ms |
31324 KB |
Output is correct |
10 |
Correct |
6 ms |
31324 KB |
Output is correct |
11 |
Correct |
7 ms |
31324 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 |
7 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 |
31324 KB |
Output is correct |
19 |
Correct |
6 ms |
31324 KB |
Output is correct |
20 |
Correct |
6 ms |
31320 KB |
Output is correct |
21 |
Correct |
6 ms |
31480 KB |
Output is correct |
22 |
Correct |
7 ms |
31324 KB |
Output is correct |
23 |
Correct |
6 ms |
31324 KB |
Output is correct |
24 |
Correct |
6 ms |
31332 KB |
Output is correct |
25 |
Correct |
6 ms |
31324 KB |
Output is correct |
26 |
Correct |
6 ms |
31324 KB |
Output is correct |
27 |
Correct |
6 ms |
31324 KB |
Output is correct |
28 |
Correct |
6 ms |
31364 KB |
Output is correct |
29 |
Correct |
6 ms |
31324 KB |
Output is correct |
30 |
Correct |
7 ms |
31364 KB |
Output is correct |
31 |
Correct |
7 ms |
31324 KB |
Output is correct |
32 |
Incorrect |
7 ms |
31452 KB |
Output isn't correct |
33 |
Halted |
0 ms |
0 KB |
- |