Submission #941655

#TimeUsernameProblemLanguageResultExecution timeMemory
941655XiaoyangA Difficult(y) Choice (BOI21_books)C++17
100 / 100
1 ms856 KiB
#include "books.h" #include <bits/stdc++.h> using namespace std; typedef long long ll; #define fi first #define se second #define pll pair<ll,ll> #define pb push_back #define debug(x) cerr<<#x<<"="<<x<<endl; #define MP make_pair #define rep(i,a,b) for(ll i=a;i<b;i++) #define SZ(x) (ll)x.size() #define ALL(x) x.begin(),x.end() #define endl "\n" const ll inf=1e18; const ll maxn=1e5+5; ll diff[maxn]; ll d(ll x){ if(diff[x])return diff[x]; return diff[x]=skim(x); } void solve(int n, int k, long long A, int s) { ll sum=0,lo=1,hi=n,id=1; vector<int>ans; rep(i,1,n+1)if(i<=k)sum+=d(i),ans.pb(i); if(sum>2*A)impossible(); if(sum>=A)answer(ans); while(lo<hi){ ll mid=(lo+hi+1)>>1; if(d(mid)<=A)lo=mid; else hi=mid-1; } if(lo+1<=n and sum-d(k)+d(lo+1)<=2*A){ ans[k-1]=lo+1; answer(ans); } while(id<=k and lo>0){ if(sum>=A)break; ans[id-1]=lo; sum-=d(id); sum+=d(lo); id++;lo--; } if(sum>=A)answer(ans); impossible(); }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...