Submission #554142

#TimeUsernameProblemLanguageResultExecution timeMemory
554142alontanayA Difficult(y) Choice (BOI21_books)C++14
100 / 100
2 ms336 KiB
#include <bits/stdc++.h> #include "books.h" #define ll long long using namespace std; ll qry[100005]; ll get(int i) { if(qry[i]) { return qry[i]; } return qry[i] = skim(i); } void solve(int N, int K, long long A, int S) { ll pre = 0; for(int i = 1; i < K; i ++) { pre += get(i); } get(K); int l = 1, r = N; while(l<r) { int mid = (l+r)/2; if(get(mid) < A) { l = mid + 1; } else { r = mid; } } if(l >= K) { if(get(l) + pre >= A && get(l) + pre <= 2 * A) { vector<int> res = {l}; for(int i = 1; i < K; i ++) { res.push_back(i); } answer(res); return; } } else { impossible(); return; } if(get(l) > A) { l --; } pre += get(K); ll suf = 0; for(int i = l; i > l - K; i --) { suf += get(i); } if(pre > 2 * A) { impossible(); return; } if(suf < A) { impossible(); return; } vector<int> res(K); for(int i = 0; i < K; i ++) { res[i] = i + 1; } int idx = 0; while(pre < A) { res[idx] = l - idx; pre -= get(idx+1); pre += get(l-idx); idx ++; } answer(res); return; }
#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...