# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
646689 | beaconmc | A Difficult(y) Choice (BOI21_books) | C++14 | 1 ms | 352 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"
typedef long long ll;
using namespace std;
#define FOR(i, x, y) for(ll i=x; i<y; i++)
#define FORNEG(i, x, y) for(ll i=x; i>y; i--)
#define fast() ios_base::sync_with_stdio(false);cin.tie(NULL)
//
// --- 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.
//
ll n,k,a,s;
map<ll,ll> cache;
ll skimm(ll x){
if (cache[x] != 0) return cache[x];
else{
cache[x] = skim(x);
return cache[x];
}
}
bool query(ll x){
ll sus = skimm(x);
if (sus*k + k*(k-1)/2 > 2*a){
return true;
}
return false;
}
void solve(int N, int K, long long A, int S) {
n = N;
k = K;
a = A;
s = S;
ll lo = 1;
ll hi = n;
while (lo<hi){
ll mid = lo + (hi - lo) / 2;
if (query(mid)){
hi = mid;
}else{
lo = mid+1;
}
}
vector<ll> sus;
ll mini = max(ll(1), lo-k);
FOR(i,lo-k, lo+k-1){
if (0<i && i<=n){
sus.push_back(skimm(i));
}
}
FOR(i,0,sus.size()-k+1){
ll suss = 0;
FOR(j,i,i+k){
suss += sus[j];
}
if (A <= suss && suss <= 2*A){
vector<int> ans;
FOR(p,i,i+k){
ans.push_back(p+mini);
}
answer(ans);
return;
}
}
ll realsus = 0;
FOR(i,1,k){
realsus += skimm(i);
}
FOR(i,0,sus.size()){
if (a<= realsus+sus[i] && realsus+sus[i] <= 2*a){
vector<int> ans;
FOR(j,1,k){
ans.push_back(j);
}
ans.push_back(i+mini);
answer(ans);
return;
}
}
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... |