# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1017602 | toast12 | A Difficult(y) Choice (BOI21_books) | C++14 | 1 ms | 596 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "books.h"
#include <vector>
#include <iostream>
using namespace std;
using ll = long long;
//
// --- 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) {
vector<int> a(K+1);
vector<ll> books(K+1);
ll sum = 0;
for (int i = 1; i <= K; i++) {
a[i] = i;
books[i] = skim(i);
sum += books[i];
}
if (sum > 2*A) {
impossible();
return;
}
if (sum >= A && sum <= 2*A) {
vector<int> ans;
for (int i = 1; i <= K; i++)
ans.push_back(a[i]);
answer(ans);
return;
}
int lo = 1, hi = N;
// find the first book larger than A
while (lo < hi) {
int mid = (lo+hi)/2;
ll x = skim(mid);
if (mid > A)
hi = mid;
else
lo = mid+1;
}
int idx = hi;
for (int i = K; i >= 1; i--) {
// move the ith book to the end
sum -= books[i];
ll x = skim(idx);
if (sum+x >= A && sum+x <= 2*A) {
a[i] = idx;
break;
}
else if (sum+x < A) {
sum += x;
books[i] = x;
a[i] = idx;
idx--;
}
else {
int l = a[i]+1, r = idx-1;
a[i] = -1;
while (l < r) {
int mid = (l+r)/2;
ll d = skim(mid);
if (sum+d >= A && sum+d <= 2*A) {
a[i] = mid;
break;
}
if (sum+d < A) {
l = mid+1;
}
else {
r = mid;
}
}
if (a[i] == -1)
impossible();
break;
}
}
vector<int> ans;
for (int i = 1; i <= K; i++) {
ans.push_back(a[i]);
}
answer(ans);
}
Compilation message (stderr)
# | 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... |