Submission #1000997

#TimeUsernameProblemLanguageResultExecution timeMemory
1000997amine_arouaA Difficult(y) Choice (BOI21_books)C++17
20 / 100
127 ms1880 KiB
#include <bits/stdc++.h> using namespace std; #define intt long long #define forr(i , x , y) for(int i = x ;i <= y;i++) #define pb push_back #define fore(i , n) for(int i = 0 ; i <n;i++) /** * skims through the i-th book and returns its difficulty x_i (1 <= i <= N). */ long long skim(int); /** * buys your selection of books. This function has to be called with * v = {i_1, ..., i_K} (1 <= i_1, ..., i_K <= N) where the i_j's are pairwise * distinct and satisfy A <= x_{i_1} + ... + x_{i_K} <= 2 A. */ void answer(std::vector<int>); /** * states that it is impossible to buy a set of K books with the desired difficulty. */ void impossible(); intt get(int i , vector<intt> &x) { if(x[i] == -1) return x[i] = skim(i); return x[i]; } void solve(int n, int k, long long a, int s) { vector<intt> x(n + 1 , -1); vector<intt> pref(n + 1); vector<int> ans; forr(i , 1 , k - 1) { pref[i] = pref[i - 1] + get(i , x); } int l = 0 , r = n; while(l + 1 < r) { int mid = (l + r)/2; if(get(mid , x) >= a) { r = mid; } else l = mid; } if(get(r , x) >= a && r >= k && get(r , x) + pref[k - 1] <= 2ll*a) { forr(i , 1, k - 1) ans.pb(i); ans.pb(r); answer(ans); return ; } int lo = k, hi = r; forr(mid , lo , hi) { intt sm = 0; forr(i , mid - k + 1 , mid) sm+=get(i , x); if(a<=sm&&sm <= 2ll * a) { forr(i , mid - k +1 , mid) ans.pb(i); answer(ans); return ; } } // while(lo + 1 < hi) // { // int mid = (lo + hi)/2; // intt sm= 0; // forr(i , mid - k + 1 , mid) // sm+=get(i , x); // if(a <= sm && sm <= 2ll * a) // { // forr(i , mid - k + 1 , mid) // ans.pb(i); // answer(ans); // return; // } // if(sm > 2ll * a) // { // hi = mid; // } // if(sm < a) // lo = mid; // } // intt sm = 0; // forr(i , lo - k +1 , lo) // { // sm+=get(i , x); // ans.pb(i); // } // if(a <= sm && sm <= 2ll * a) // { // answer(ans); // 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...