Submission #889629

#TimeUsernameProblemLanguageResultExecution timeMemory
889629shiomusubi496A Difficult(y) Choice (BOI21_books)C++17
0 / 100
1 ms1112 KiB
#include <bits/stdc++.h> #include "books.h" using namespace std; #define rep(i, n) for (int i = 0; i < (int)(n); ++i) #define rrep(i, n) for (int i = (int)(n) - 1; i >= 0; --i) using ll = long long; void solve(int N, int K, long long A, int S) { auto my_skim = [&](int pos) { static vector<ll> memo(N, -1); if (memo[pos] != -1) return memo[pos]; return memo[pos] = skim(pos + 1); }; ll sm = 0; rep (i, K - 1) sm += my_skim(i); int ok = K - 1, ng = N; while (ng - ok > 1) { int mid = (ok + ng) / 2; if (sm + my_skim(mid) < A) ok = mid; else ng = mid; } if (sm + my_skim(ok + 1) <= 2 * A) { vector<int> ans; rep (i, K - 1) ans.push_back(i + 1); ans.push_back(ok + 2); answer(ans); return; } if (ok == K - 1) { impossible(); return; } sm += my_skim(ok); rep (i, K - 1) { sm -= my_skim(K - 2 - i); sm += my_skim(ok - i - 1); if (sm >= A) { vector<int> ans; rep (j, K - 2 - i) ans.push_back(j + 1); rrep (j, i + 2) ans.push_back(ok - j + 1); 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...