QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#128595 | #6625. Binaria | SanguineChameleon | 0 | 2ms | 11724kb | C++20 | 1.3kb | 2023-07-21 12:27:24 | 2023-07-21 12:27:25 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
void just_do_it();
int main() {
#ifdef KAMIRULEZ
freopen("kamirulez.inp", "r", stdin);
freopen("kamirulez.out", "w", stdout);
#endif
ios_base::sync_with_stdio(0);
cin.tie(0);
just_do_it();
return 0;
}
const int maxn = 1e6 + 3;
const long long mod = 1e6 + 3;
int sum[maxn];
int a[maxn];
long long inv[maxn];
long long fact[maxn];
long long fact_inv[maxn];
void just_do_it() {
int n, k;
cin >> n >> k;
for (int i = 0; i < n - k + 1; i++) {
cin >> sum[i];
}
for (int i = 0; i < k; i++) {
a[i] = -1;
for (int j = i; j + k < n; j += k) {
if (sum[j] != sum[j + 1]) {
if (sum[j] > sum[j + 1]) {
a[j] = 1;
}
else {
a[j] = 0;
}
while (j > i) {
j -= k;
a[j] = a[j + k] + sum[j] - sum[j + 1];
}
}
}
}
int rem = sum[0];
int cnt = 0;
for (int i = 0; i < k; i++) {
if (a[i] == -1) {
cnt++;
}
else {
rem -= a[i];
}
}
inv[1] = fact[0] = fact[1] = fact_inv[0] = fact_inv[1] = 1;
for (int i = 2; i <= cnt; i++) {
inv[i] = (mod - mod / i) * inv[mod % i] % mod;
fact[i] = fact[i - 1] * i % mod;
fact_inv[i] = fact_inv[i - 1] * inv[i] % mod;
}
cout << fact[cnt] * fact_inv[rem] % mod * fact_inv[cnt - rem] % mod;
}
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 0
Time Limit Exceeded
Test #1:
score: 3
Accepted
time: 2ms
memory: 11600kb
input:
1 1 0
output:
1
result:
ok 1 number(s): "1"
Test #2:
score: 0
Accepted
time: 2ms
memory: 11612kb
input:
1 1 1
output:
1
result:
ok 1 number(s): "1"
Test #3:
score: 0
Accepted
time: 2ms
memory: 11724kb
input:
10 3 1 2 2 2 2 2 2 2
output:
2
result:
ok 1 number(s): "2"
Test #4:
score: -3
Time Limit Exceeded
input:
10 3 1 1 0 1 2 3 2 2
output:
result:
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%