이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#include "books.h"
using namespace std;
//
// --- Sample implementation for the task books ---
//
// To compile this program with the sample grader, place:
// books.h books_sample.cpp sample_grader.cpp
// in a single folder and run:
// g++ books_sample.cpp sample_grader.cpp
// in this folder.
//
map<int, long long> m;
long long skim_and_check(int x) {
if (m.count(x)) {
return m[x];
} else {
return m[x] = skim(x);
}
}
void answer_and_sort(vector<int> v) {
sort(v.begin(), v.end());
answer(v);
}
void solve(int N, int K, long long A, int S) {
m = map<int, long long>();
int l = 0, r = N + 1;
while (r > l + 1) {
int mid = (l + r) / 2;
if (skim_and_check(mid) < A) {
l = mid;
} else {
r = mid;
}
}
if (l < K) {
long long sum = 0;
vector<int> ans;
for (int i = 1; i <= K; i++) {
sum += skim_and_check(i);
ans.push_back(i);
}
if (sum >= A && sum <= 2 * A) {
answer_and_sort(ans);
} else {
impossible();
}
return;
}
vector<int> ans;
vector<long long> vals;
long long sum = 0;
for (int i = l; i > l - K; i--) {
vals.push_back(skim_and_check(i));
ans.push_back(i);
sum += vals.back();
}
if (sum < A) {
if (r == N + 1) {
impossible();
return;
}
sum = skim_and_check(r);
ans = vector<int>();
ans.push_back(r);
for (int i = 1; i <= K - 1; i++) {
ans.push_back(i);
sum += skim_and_check(i);
}
if (sum <= 2 * A) {
answer_and_sort(ans);
} else {
impossible();
}
} else {
if (sum <= 2 * A) {
answer_and_sort(ans);
return;
}
vector<int> add;
for (int i = 1; i <= K; i++) {
sum += skim_and_check(i) - vals.back();
vals.pop_back();
ans.pop_back();
add.push_back(i);
if (sum <= 2 * A) {
break;
}
}
if (sum > 2 * A) {
impossible();
return;
}
vector<int> new_ans;
for (int v : add) {
new_ans.push_back(v);
}
for (int v : ans) {
new_ans.push_back(v);
}
answer_and_sort(new_ans);
}
}
# | 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... |