이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#include <books.h>
#pragma GCC optimize ("trapv")
using namespace std;
typedef long long ll;
bool check (ll sum, ll a) {
return sum >= a && sum <= 2 * a;
}
void solve (int n, int k, ll a, int s) {
map <int, ll> dd;
int l = k, r = n;
for (int i = 1; i < k; i++) dd[i] = skim(i);
int ans = -1;
while (l <= r) {
int mid = (l + r) >> 1;
if (!dd.count(mid)) dd[mid] = skim(mid);
if (dd[mid] > a) {
r = mid - 1; ans = mid;
} else {
l = mid + 1;
}
}
ll sum = 0;
for (int i = 1; i < k; i++) sum += dd[i];
if (ans != -1) {
sum += dd[ans];
if (check(sum, a)) {
vector <int> t;
for (int i = 1; i < k; i++) t.push_back(i);
t.push_back(ans);
answer(t);
}
}
if (ans == -1) ans = n + 1;
if (!dd.count(k)) dd[k] = skim(k);
vector <pair <int, ll>> u;
for (int i = 1; i <= k; i++) {
if (!dd.count(i)) dd[i] = skim(i);
u.push_back({i, dd[i]});
}
for (int i = max(1, ans - k); i < ans; i++) {
if (!dd.count(i)) dd[i] = skim(i);
u.push_back({i, dd[i]});
}
sum = 0;
for (int i = 0; i < k; i++) sum += u[i].second;
if (check(sum, a)) {
vector <int> t;
for (int i = 0; i < k; i++) t.push_back(u[i].first);
sort(t.begin(), t.end());
answer(t);
}
for (int i = k; i < (int)u.size(); i++) {
sum -= u[i - k].second;
sum += u[i].second;
if (check(sum, a)) {
vector <int> t;
for (int j = i - k + 1; j <= i; j++) {
t.push_back(u[j].first);
}
sort(t.begin(), t.end());
answer(t);
}
}
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... |