Submission #409228

#TimeUsernameProblemLanguageResultExecution timeMemory
409228jamielimA Difficult(y) Choice (BOI21_books)C++14
100 / 100
2 ms1072 KiB
#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.cpp grader.cpp // in a single folder and run: // g++ books.cpp grader.cpp // in this folder. // #define fi first #define se second #define mp make_pair #define pb emplace_back #define ALL(x) x.begin(),x.end() #define SZ(x) (int)x.size() typedef long long ll; typedef pair<int,int> ii; typedef pair<ii,ii> i4; const int MOD=1000000007; const int INF=1012345678; const ll LLINF=1012345678012345678LL; const double PI=3.1415926536; const double EPS=1e-14; ll arr[100005]; ll get(int x){ if(arr[x]==-1)arr[x]=skim(x); return arr[x]; } void solve(int N, int K, long long A, int S) { memset(arr,-1,sizeof(arr)); int l=1,r=N; while(l<r){ int m=(l+r+1)/2; if(get(m)<A){ l=m; }else{ r=m-1; } } if(l<=K-2){ impossible(); return; } if(l==K-1){ ll sum=0; vector<int> v; for(int i=1;i<=K;i++){ sum+=get(i); v.pb(i); } if(sum<A||sum>2*A)impossible(); // sum<A should not happen since get(K)>=A else answer(v); return; } ll small=0,large=0; for(int i=1;i<=K;i++)small+=get(i); for(int i=l;i>l-K;i--)large+=get(i); if(small>2*A){impossible();return;} if(large<A){ vector<int> v;for(int i=1;i<K;i++)v.pb(i);v.pb(l+1); if(l+1<=N&&small-get(K)+get(l+1)<=2*A)answer(v); else impossible(); return; } // small<=2A, large>=A ll sum=small; for(int i=K;i>=1;i--){ if(sum>=A){ vector<int> v; for(int j=1;j<=i;j++){ v.pb(j); } for(int j=l-K+i+1;j<=l;j++){ v.pb(j); } answer(v); return; } sum-=get(i); sum+=get(l-K+i); } if(sum>=A){ vector<int> v; for(int j=l-K+1;j<=l;j++)v.pb(j); answer(v); return; } 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...