QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#117356 | #6625. Binaria | Qwerty1232# | 0 | 0ms | 3716kb | C++23 | 2.4kb | 2023-07-01 01:30:32 | 2024-05-31 18:44:48 |
Judging History
answer
#include <bits/stdc++.h>
constexpr int mod = 1e6 + 3;
int add(int a, int b) {
return a + b - mod * (a + b >= mod);
}
int mul(int a, int b) {
return a * 1ULL * b % mod;
}
int power(int b, int e) {
int r = 1;
for (; e > 0; e >>= 1) {
if (e & 1) {
r = mul(r, b);
}
b = mul(b, b);
}
return r;
}
int fuck(int n) {
int r = 1;
for (int i = 1; i <= n; i++) {
r = mul(r, i);
}
return r;
}
int C(int n, int k) {
return mul(fuck(n), power(mul(fuck(n - k), fuck(k)), mod - 2));
}
void zero() {
std::cout << 0 << std::endl;
exit(0);
}
int32_t main() {
std::ios_base::sync_with_stdio(false);
std::cin.tie(nullptr);
int n, k;
std::cin >> n >> k;
std::vector<int> input(n - k + 1);
for (int& i : input) {
std::cin >> i;
}
std::vector<int> cum(n, -1);
int ans = 0;
for (int i = 0; i < n - k; i++) {
if (cum[i] == -1) {
if (input[i] != input[i + 1]) {
cum[i] = input[i] < input[i + 1];
cum[i + k] = input[i] > input[i + 1];
for (int j = i - k; j >= 0; j -= k) {
cum[j] = cum[j + k] + input[j] - input[j + 1];
if (cum[j] < 0 || cum[j] > 1) {
zero();
}
}
for (int j = i + 2 * k; j < n; j += k) {
cum[j] = cum[j - k] - input[j - k] + input[j - k + 1];
if (cum[j] < 0 || cum[j] > 1) {
zero();
}
}
}
}
}
std::vector<int> dlt(input.size(), 0);
for (int i = 0; i < n; i++) {
if (cum[i] == 1) {
dlt[std::max(0, i - k + 1)]--;
if (i + 1 < input.size()) {
dlt[i + 1]++;
}
}
}
for (int i = 0, c = 0; i < input.size(); i++) {
c += dlt[i];
input[i] += c;
}
if (!std::all_of(input.begin(), input.end(), std::bind(std::equal_to<int>(), std::placeholders::_1, input.front()))) {
zero();
}
int cnt = 0;
for (int i = 0; i < k; i++) {
cnt += cum[i] == -1;
}
int cnt2 = input[0];
if (cnt2 < 0 || cnt2 > cnt) {
zero();
}
ans = C(cnt, cnt2);
ans %= mod;
std::cout << ans << "\n";
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 3
Accepted
time: 0ms
memory: 3508kb
input:
1 1 0
output:
1
result:
ok 1 number(s): "1"
Test #2:
score: 0
Accepted
time: 0ms
memory: 3520kb
input:
1 1 1
output:
1
result:
ok 1 number(s): "1"
Test #3:
score: -3
Wrong Answer
time: 0ms
memory: 3716kb
input:
10 3 1 2 2 2 2 2 2 2
output:
0
result:
wrong answer 1st numbers differ - expected: '2', 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%