Submission #1017602

#TimeUsernameProblemLanguageResultExecution timeMemory
1017602toast12A Difficult(y) Choice (BOI21_books)C++14
25 / 100
1 ms596 KiB
#include "books.h" #include <vector> #include <iostream> using namespace std; using ll = long long; // // --- 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. // void solve(int N, int K, long long A, int S) { vector<int> a(K+1); vector<ll> books(K+1); ll sum = 0; for (int i = 1; i <= K; i++) { a[i] = i; books[i] = skim(i); sum += books[i]; } if (sum > 2*A) { impossible(); return; } if (sum >= A && sum <= 2*A) { vector<int> ans; for (int i = 1; i <= K; i++) ans.push_back(a[i]); answer(ans); return; } int lo = 1, hi = N; // find the first book larger than A while (lo < hi) { int mid = (lo+hi)/2; ll x = skim(mid); if (mid > A) hi = mid; else lo = mid+1; } int idx = hi; for (int i = K; i >= 1; i--) { // move the ith book to the end sum -= books[i]; ll x = skim(idx); if (sum+x >= A && sum+x <= 2*A) { a[i] = idx; break; } else if (sum+x < A) { sum += x; books[i] = x; a[i] = idx; idx--; } else { int l = a[i]+1, r = idx-1; a[i] = -1; while (l < r) { int mid = (l+r)/2; ll d = skim(mid); if (sum+d >= A && sum+d <= 2*A) { a[i] = mid; break; } if (sum+d < A) { l = mid+1; } else { r = mid; } } if (a[i] == -1) impossible(); break; } } vector<int> ans; for (int i = 1; i <= K; i++) { ans.push_back(a[i]); } answer(ans); }

Compilation message (stderr)

books.cpp: In function 'void solve(int, int, long long int, int)':
books.cpp:41:12: warning: unused variable 'x' [-Wunused-variable]
   41 |         ll x = skim(mid);
      |            ^
#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...