# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
721166 | FatihSolak | A Difficult(y) Choice (BOI21_books) | C++17 | 1 ms | 336 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 <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.
//
int cnt = 0;
long long get(int pos){
assert(cnt++ <= 40);
return skim(pos);
}
void solve(int n, int k, long long a, int s){
int l = 1,r = n+1;
while(l < r){
int m = (l+r)/2;
if(get(m) < a){
l = m + 1;
}
else r = m;
}
vector<pair<int,long long>> x;
vector<pair<int,long long>> y;
for(int i = 1;i<=k;i++){
x.push_back({i,get(i)});
}
if(l < k){
impossible();
return;
}
if(l != n+1){
long long sum = get(l);
for(int i = 0;i<k-1;i++){
sum += x[i].second;
}
if(a <= sum && sum <= 2*a){
vector<int> ret;
for(int i = 1;i<=k-1;i++){
ret.push_back(i);
}
ret.push_back(l);
assert(ret.size() == k);
answer(ret);
return;
}
}
if(l == k){
impossible();
return;
}
for(int i = k;i>=1;i--){
y.push_back({l-i,get(l-i)});
}
long long sum = 0;
for(auto u:x){
sum += u.second;
}
if(a <= sum && sum <= 2*a){
vector<int> ret;
for(int i = 1;i<=k;i++){
ret.push_back(i);
}
assert(ret.size() == k);
answer(ret);
return;
}
if(sum > 2*a){
impossible();
return;
}
for(int i = 1;i<=k;i++){
sum -= x[k-i].second;
sum += y[k-i].second;
if(a <= sum && sum <= 2*a){
vector<int> ret;
for(int j = 1;j<=k-i;j++){
ret.push_back(i);
}
for(int j = k-1;j>=k-i;j--){
ret.push_back(y[j].first);
}
assert(ret.size() == k);
answer(ret);
sort(ret.begin(),ret.end());
return;
}
assert(sum < a);
}
impossible();
}
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... |