Submission #981606

#TimeUsernameProblemLanguageResultExecution timeMemory
981606OAleksaA Difficult(y) Choice (BOI21_books)C++14
45 / 100
1 ms856 KiB
#include <bits/stdc++.h> #include "books.h" using namespace std; const int N = 1e5 + 69; long long was[N], sum = 0; // // --- 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) { int l = 1, r = n, lst = -1; vector<int> ans; while (l <= r) { int mid = (l + r) / 2; long long b = 0; if (was[mid] > 0) b = was[mid]; else b = skim(mid); was[mid] = b; if (b >= a) { lst = mid; r = mid - 1; } else l = mid + 1; } if (lst == -1) { for (int i = n, j = 0;i >= 1, j < k;j++, i--) { if (!was[i]) was[i] = skim(i); sum += was[i]; } if (sum < a) impossible(); else if (sum >= a && sum <= 2 * a) { for (int i = n,j = 0;i >= 1,j < k;i--,j++) ans.push_back(i); answer(ans); } long long ss = 0; for (int i = 1;i <= k;i++) { if (!was[i]) was[i] = skim(i); ss += was[i]; } if (ss > 2 * a) impossible(); else if (ss >= a && ss <= 2 * a) { for (int i = 1;i <= k;i++) ans.push_back(i); answer(ans); } int ptr = n, d = 0; while (d < k) { sum -= was[ptr]; sum += was[n - ptr + 1]; ptr--; d++; if (sum >= a && sum <= 2 * a) break; } for (int i = 1;i <= d;i++) ans.push_back(i); for (int i = n - k + 1;i <= ptr;i++) ans.push_back(i); assert(sum >= a && sum <= 2 * a); answer(ans); } else if (lst < k) impossible(); for (int i = 1;i <= k - 1;i++) { was[i] = skim(i); sum += was[i]; } sum += was[lst]; if (sum >= a && sum <= 2 * a) { for (int i = 1;i <= k - 1;i++) ans.push_back(i); ans.push_back(lst); answer(ans); } sum -= was[lst]; long long t = a - sum; if (sum >= a) { sum = 0; for (int i = 1;i <= k;i++) { ans.push_back(i); if (!was[i]) was[i] = skim(i); sum += was[i]; } if (sum >= a && sum <= 2 * a) answer(ans); assert(sum >= a); impossible(); } int ll = k - 1; l = k, r = lst - 1; int id = -1; for (int i = k;i < lst;i++) { if (was[i]) { if (t >= was[ll] && t <= was[i]) l = ll, r = i; ll = i; } } while (l <= r) { int mid = (l + r) / 2; long long b = 0; if (was[mid]) b = was[mid]; else b = skim(mid); was[mid] = b; if (b < t) { id = mid; l = mid + 1; } else r = mid - 1; } if (id == -1 || id + 1 == lst) impossible(); for (int i = 1;i <= k - 1;i++) ans.push_back(i); ans.push_back(id + 1); long long ss = sum + skim(id + 1); assert(ss >= a && ss <= 2 * a); answer(ans); }

Compilation message (stderr)

books.cpp: In function 'void solve(int, int, long long int, int)':
books.cpp:37:27: warning: left operand of comma operator has no effect [-Wunused-value]
   37 |   for (int i = n, j = 0;i >= 1, j < k;j++, i--) {
      |                         ~~^~~~
books.cpp:45:27: warning: left operand of comma operator has no effect [-Wunused-value]
   45 |    for (int i = n,j = 0;i >= 1,j < k;i--,j++)
      |                         ~~^~~~
#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...