이 제출은 이전 버전의 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.
//
void solve(int N, int K, long long A, int S) {
long long L = 1, R = N;
long long omk = 0;
long long ans[N + 1];
for(long long i = 0; i < N + 1; i++) {
ans[i] = -1;
}
while(L <= R) {
long long mid = (L + R) >> 1;
ans[mid] = skim(mid);
if(ans[mid] <= A) {
L = mid + 1;
omk = mid;
}
else {
R = mid - 1;
}
}
for(long long i = 1; i <= K; i++) {
//cout << "i = " << i << "\n";
if(ans[i] == -1) {
ans[i] = skim(i);
}
}
//cout << "omk = " << omk << ", K = " << K << "\n";
for(long long i = omk; i > max(omk - K, 0LL); i--) {
//cout << "i = " << i << "\n";
if(ans[i] == -1) {
ans[i] = skim(i);
}
}
long long value = 0;
vector<int> res;
set<long long> res2;
for(long long i = 1; i <= K; i++) {
value += ans[i];
res.push_back(i);
res2.insert(i);
}
if(value >= A && value <= 2LL * A) {
answer(res);
return;
}
long long cnt = 1;
for(long long i = omk; i > max(omk - K, 0LL); i--) {
if(res2.count(i))
continue;
res2.erase(cnt);
res2.insert(i);
res.erase(res.begin());
res.push_back(i);
value -= ans[cnt];
value += ans[i];
cnt++;
if(value >= A && value <= 2LL * A) {
answer(res);
return;
}
}
if(omk == N || omk < K + 1) {
impossible();
return;
}
ans[omk + 1] = skim(omk + 1);
res.clear();
value = 0;
for(long long i = 1; i < K; i++) {
res.push_back(i);
value += ans[i];
}
res.push_back(omk + 1);
value += ans[omk + 1];
if(value >= A && value <= 2LL * A) {
answer(res);
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... |