이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "books.h"
#include <bits/stdc++.h>
typedef long long ll;
void solve(int n, int k, ll a, int s) {
std::vector <ll> vals(n + 1, -1), use;
vals[n] = skim(n);
if (vals[n] * ll(k) < a) {
impossible();
return;
}
int l = k, r = n;
while (l < r) {
int mid = (l + r) >> 1;
if (vals[mid] == -1LL) vals[mid] = skim(mid);
if (ll(k) * vals[mid] >= a) r = mid;
else l = mid + 1;
}
std::vector <int> res;
ll sum = 0;
for (int i = 1 + l - k; i < l + 1; i++) {
if (vals[i] == -1LL) vals[i] = skim(i);
res.push_back(i);
use.push_back(vals[i]);
}
for (ll x : use) sum += x;
if (a <= sum) {
if (sum <= a + a) answer(res);
else impossible();
return;
}
for (int i = l + 1; i < 1 + l + k; i++) {
if (vals[i] == -1LL) vals[i] = skim(i);
sum += vals[i];
sum -= use[i - l - 1];
res.push_back(i);
if (a <= sum && sum <= a + a) {
std::vector <int> ans;
for (int j = i - l; j < (int)res.size(); j++) {
ans.push_back(res[j]);
}
answer(ans);
return;
} else if (sum > a + a) {
ll newsum = vals[i];
std::vector <int> ans = { i };
for (int j = 1; j < k; j++) {
ans.push_back(j);
if (vals[j] == -1LL) vals[j] = skim(j);
newsum += vals[j];
}
if (newsum >= a && newsum <= a + a) {
std::sort(ans.begin(), ans.end()); // ???
answer(ans);
return;
}
impossible();
return;
}
}
impossible();
}
# | 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... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |