이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#include "books.h"
using namespace std;
//code
//skim() impossible() answer({});
#include <bits/stdc++.h>
#define show(x,y) cout << y << " " << #x << endl;
#define show2(x,y,i,j) cout << y << " " << #x << " " << j << " " << #i << endl;
#define show3(x,y,i,j,p,q) cout << y << " " << #x << " " << j << " " << #i << " " << q << " " << #p << endl;
#define show4(x,y) for(auto it:y) cout << it << " "; cout << #x << endl;
long long memo[100005];
long long ask(int n){
if(memo[n]!=-1) return memo[n];
return memo[n]=skim(n);
}
void solve(int n, int k, long long a, int s) {
memset(memo,-1,sizeof(memo));
long long hold=ask(n);
vector<int>v;
if(hold>=a){
long long counter=0;
for(int x=1;x<k;x++){
v.push_back(x);
counter+=ask(x);
}
int l=k;
int r=n;
int mid;
int best=r;
while(l<=r){
mid=(l+r)/2;
long long take=ask(mid);
if(take>=a){
best=mid;
r=mid-1;
}
else l=mid+1;
}
long long hold=counter;
if(best<k) hold+=ask(k);
else hold+=ask(best);
if(hold>=a&&hold<=2*a){
for(int x=1;x<k;x++){
v.push_back(x);
}
if(best<k) v.push_back(k);
else v.push_back(best);
answer(v);
return;
}
n=best-1;
}
long long counter=0;
vector<pair<long long,long long>>cur;
for(int x=1;x<=k;x++){
cur.push_back({ask(x),x});
counter+=cur.back().first;
}
int ptr=n;
//show(counter,counter);
if(n<k||(n<=k&&counter<a)||counter>2*a){
impossible();
return;
}
while(counter<a&&!cur.empty()){
counter+=ask(ptr);
v.push_back(ptr);
ptr--;
counter-=cur.back().first;
cur.pop_back();
}
if(counter>=a){
for(auto it:cur) v.push_back(it.second);
answer(v);
return;
}
impossible();
}
//code
# | 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... |