Submission #720220

#TimeUsernameProblemLanguageResultExecution timeMemory
720220JohannA Difficult(y) Choice (BOI21_books)C++14
30 / 100
248 ms976 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_sample.cpp sample_grader.cpp // in a single folder and run: // g++ books_sample.cpp sample_grader.cpp // in this folder. // typedef long long ll; typedef vector<ll> vi; #define sz(x) (int)(x).size() ll A; int N, K, S; vi store; ll mySkim(int x) { assert(1 <= x && x <= N); if (store[x] == -1) store[x] = skim(x); return store[x]; } void myImpossible() { impossible(); } void myAnswer(vi &ans) { assert(sz(ans) == K); ll checkSum = 0; vector<int> yourAns; for (ll x : ans) yourAns.push_back((int)x), checkSum += mySkim((int)x); assert(A <= checkSum && checkSum <= 2 * A); answer(yourAns); } void solve(int _N, int _K, long long _A, int _S) { A = _A, N = _N, K = _K, S = _S; store.assign(N + 1, -1); // starting with 1 index if (S == N) { for (int i = 1; i <= N; ++i) mySkim(i); ll psum = 0; for (int i = 1; i <= K; ++i) psum += mySkim(i); if (psum > 2 * A) myImpossible(); int idx = 1; while (idx + K <= N && psum < A) { psum -= mySkim(idx); psum += mySkim(idx + K); ++idx; } if (psum > 2 * A) { assert(mySkim(idx + K - 1) > A); vi ans; psum = 0; for (int i = 1; i <= K - 1; ++i) ans.push_back(i), psum += mySkim(i); ans.push_back(idx + K - 1), psum += mySkim(idx + K - 1); if (psum <= 2 * A) myAnswer(ans); else myImpossible(); } else if (psum >= A) { vi ans; for (int i = idx; i < idx + K; ++i) ans.push_back(i); myAnswer(ans); } else myImpossible(); } else { int l = 1, r = N, m; while (l < r) { m = (l + r) / 2; if (mySkim(m) > (2 * A) / K) r = m - 1; else if (mySkim(m) < ceil(A / (double)K)) l = m + 1; else l = r = m; } int idx = max(1, l - K + 1); ll psum = 0; for (int i = idx; i < idx + K; ++i) psum += mySkim(i); do { if (A <= psum && psum <= 2 * A) { vi ans; for (int i = idx; i < idx + K; ++i) ans.push_back(i); myAnswer(ans); return; } psum -= mySkim(idx); psum += mySkim(idx + K); ++idx; } while (idx <= min(N, l + K - 1)); myImpossible(); } }
#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...