This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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 (stderr)
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 |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |