Submission #917004

#TimeUsernameProblemLanguageResultExecution timeMemory
917004NK_A Difficult(y) Choice (BOI21_books)C++17
20 / 100
35 ms600 KiB
// Success consists of going from failure to failure without loss of enthusiasm #include <bits/stdc++.h> #include "books.h" using namespace std; #define nl '\n' #define f first #define s second #define mp make_pair #define pb push_back using ll = long long; template<class T> using V = vector<T>; using vi = V<int>; using pl = pair<ll, ll>; using vpl = V<pl>; // g++-13 A.cpp grader.cpp void solve(int N, int K, ll A, int S) { int Q = 0; auto ask = [&](int x) { ++Q; if (Q > S) exit(0-0); return skim(x + 1); }; int lo = 0, hi = N - 1; for(int r = 0; r < 18; r++) { if (lo >= hi) break; int mid = (lo + hi) / 2; if (ask(mid) >= A) hi = mid; else lo = mid + 1; } lo = min(N - 1, lo); set<int> look; for(int i = 0; i < K; i++) { look.insert(i); look.insert(lo - i); } vpl X; for(auto& i : look) X.pb(mp(ask(i), i)); // for(auto& p : X) cout << "(" << p.f << ", " << p.s << ") "; // cout << endl; int M = int(size(X)); assert(M <= 2 * K && S >= 0); for(int msk = 0; msk < (1 << M); msk++) { if (__builtin_popcount(msk) != K) continue; ll sum = 0; vi res; for(int i = 0; i < M; i++) if ((msk >> i) & 1) { res.pb(X[i].s + 1); sum += X[i].f; } assert(int(size(res)) == K); if (A <= sum && sum <= 2LL * A) { answer(res); 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...