QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#117219 | #6625. Binaria | pandapythoner# | 0 | 0ms | 0kb | C++20 | 2.1kb | 2023-06-30 17:51:57 | 2024-05-31 18:43:20 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define flt double
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
mt19937 rnd(234);
const ll inf = 1e9;
const ll mod = 1e6 + 3;
ll bin_pow(ll x, ll n) {
if (n == 0) {
return 1;
}
ll a = bin_pow(x, n / 2);
a = (a * a) % mod;
if (n & 1) {
a = (a * x) % mod;
}
return a;
}
ll rev(ll x) {
return bin_pow(x, mod - 2);
}
vector<ll> fct;
vector<ll> rv_fct;
ll build_fct(int n) {
fct.resize(n + 1);
rv_fct.resize(n + 1);
fct[0] = 1;
rv_fct[0] = 1;
for (int i = 1; i <= n; i += 1) {
fct[i] = (fct[i - 1] * i) % mod;
rv_fct[i] = rev(fct[i]);
}
}
ll cnk(int n, int k) {
if (k < 0 || k > n) {
return 0;
}
return fct[n] * rv_fct[k] % mod * rv_fct[n - k] % mod;
}
int n, k;
vector<ll> a;
ll solve() {
build_fct(n + 100);
if (k == 1) {
return 1;
}
vector<ll> d(n + 1, 0);
for (int i = 0; i < n - k + 1; i += 1) {
d[i + k] = d[i] + a[i];
}
vector<pair<ll, ll>> bebra(k, {-inf, inf});
for (int i = 0; i + 1 <= n; i += 1) {
int x = i % k;
int y = (i + 1) % k;
ll dx = d[i];
ll dy = d[i + 1];
bebra[x].first = max(bebra[x].first, dx - dy);
bebra[x].second = min(bebra[x].second, dx + 1 - dy);
}
int bg = 0;
int cnk_n = 0;
for (int i = 0; i + 1 < k; i += 1) {
if (bebra[i].first == 1) {
bg += 1;
} else if (bebra[i].second == 1) {
cnk_n += 1;
}
}
ll rs = 0;
ll l = -bebra[k - 1].second;
ll r = -bebra[k - 1].first;
for (ll t = l; t <= r; t += 1) {
rs = (rs + cnk(cnk_n, t - bg)) % mod;
}
return rs;
}
int32_t main() {
if (1) {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
}
cin >> n >> k;
a.assign(n - k + 1, 0);
for (int i = 0; i < n - k + 1; i += 1) {
cin >> a[i];
}
cout << solve() << "\n";
return 0;
}
詳細信息
Subtask #1:
score: 0
Runtime Error
Test #1:
score: 0
Runtime Error
input:
1 1 0
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%