# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
936326 | Trisanu_Das | Binaria (CCO23_day1problem1) | C++17 | 97 ms | 21332 KiB |
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 <stdio.h>
#define N 1000000
#define MD 1000003
int vv[N + 1], ff[N + 1], gg[N + 1];
void init() {
int i;
ff[0] = gg[0] = 1;
for (i = 1; i <= N; i++) {
vv[i] = i == 1 ? 1 : (long long) vv[i - MD % i] * (MD / i + 1) % MD;
ff[i] = (long long) ff[i - 1] * i % MD;
gg[i] = (long long) gg[i - 1] * vv[i] % MD;
}
}
int choose(int n, int k) {
return k < 0 || k > n ? 0 : (long long) ff[n] * gg[k] % MD * gg[n - k] % MD;
}
int main() {
static int kk[N];
int n, k, i, r, a, k1, k01;
init();
scanf("%d%d", &n, &k);
for (i = 0; i + k <= n; i++)
scanf("%d", &kk[i]);
k01 = k1 = 0;
for (r = 0; r < k; r++) {
a = -1;
for (i = r; i + k < n; i += k)
if (kk[i + 1] != kk[i]) {
if (kk[i + 1] - kk[i] == 1)
a = 0;
else if (kk[i + 1] - kk[i] == -1)
a = 1;
else
a = -2;
break;
}
if (a == -2) {
printf("0\n");
return 0;
}
if (a == -1) {
k01++;
continue;
}
if (a == 1)
k1++;
for (i = r; i + k < n; i += k) {
a += kk[i + 1] - kk[i];
if (a != 0 && a != 1) {
printf("0\n");
return 0;
}
}
}
printf("%d\n", choose(k01, kk[0] - k1));
return 0;
}
Compilation message (stderr)
# | 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... |