QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#117529 | #6625. Binaria | valerikk# | 0 | 8ms | 16176kb | C++17 | 1.6kb | 2023-07-01 15:29:37 | 2024-05-31 18:45:41 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
const int N = 105;
#else
const int N = 1e6 + 7;
#endif
const int md = 1e6 + 3;
int mul(int a, int b) {
return a * 1ll * b % md;
}
int pw(int a, int n) {
int ret = 1;
while (n > 0) {
if (n & 1) {
ret = mul(ret, a);
}
a = mul(a, a);
n >>= 1;
}
return ret;
}
int f[N], rf[N];
int n, k;
int s[N];
int a[N];
int kek[N];
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
f[0] = 1;
for (int i = 1; i < N; ++i) {
f[i] = mul(f[i - 1], i);
}
rf[N - 1] = pw(f[N - 1], md - 2);
for (int i = N - 2; i >= 0; --i) {
rf[i] = mul(rf[i + 1], i + 1);
}
cin >> n >> k;
for (int i = 0; i < n - k + 1; ++i) {
cin >> s[i];
}
for (int i = 0; i < n; ++i) {
a[i] = -1;
}
for (int i = 0; i < n - k; ++i) {
if (s[i] + 1 == s[i + 1]) {
a[i] = 0;
a[i + k] = 1;
}
if (s[i] - 1 == s[i + 1]) {
a[i] = 1;
a[i + k] = 0;
}
}
for (int i = 0; i < n - k; ++i) {
if (s[i] == s[i + 1] && a[i] != -1) {
if (a[i + k] != -1 && a[i + k] != a[i]) {
cout << "0\n";
return 0;
}
a[i + k] = a[i];
}
}
for (int i = n - k - 1; i >= 0; --i) {
if (s[i] == s[i + 1] && a[i + k] != -1) {
if (a[i] != -1 && a[i] != a[i + k]) {
cout << "0\n";
return 0;
}
a[i] = a[i + k];
}
}
for (int i = 0; i < n; ++i) {
if (a[i] != -1) {
++kek[i % k];
}
}
int cnt = 0;
for (int i = 0; i < k; ++i) {
if (kek[i] == 0) {
++cnt;
}
}
int need = s[0];
for (int i = 0; i < k; ++i) {
if (a[i] != -1) {
need -= a[i];
}
}
if (need < 0 || need > cnt) {
cout << "0\n";
return 0;
}
cout << mul(f[cnt], mul(rf[need], rf[cnt - need])) << "\n";
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 0
Wrong Answer
time: 8ms
memory: 16176kb
input:
1 1 0
output:
0
result:
wrong answer 1st numbers differ - expected: '1', found: '0'
Subtask #2:
score: 0
Skipped
Dependency #1:
0%
Subtask #3:
score: 0
Skipped
Dependency #2:
0%
Subtask #4:
score: 0
Skipped
Dependency #3:
0%
Subtask #5:
score: 0
Skipped
Dependency #4:
0%
Subtask #6:
score: 0
Skipped
Dependency #5:
0%