# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
730511 | nguyentunglam | A Difficult(y) Choice (BOI21_books) | C++17 | 2 ms | 432 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#include "books.h"
using namespace std;
const int N = 1e5 + 10;
long long a[N];
//
// --- 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.
//
long long Skim(int i) {
if (a[i]) return a[i];
return a[i] = skim(i);
}
void solve(int n, int k, long long A, int s) {
// // TODO implement this function
int l = 1, r = n;
long long v = 0;
int p = n + 1;
while (l <= r) {
int mid = l + r >> 1;
long long tmp = Skim(mid);
if (tmp >= A) {
v = tmp; p = mid;
r = mid - 1;
}
else l = mid + 1;
}
for(int i = 1; i <= k - 1; i++) v += Skim(i);
vector<int> ret;
if (p <= n && k - 1 < p && v <= A * 2) {
for(int i = 1; i <= k - 1; i++) ret.push_back(i);
ret.push_back(p);
answer(ret);
}
long long cur = 0;
for(int i = k; i >= 1; i--) {
ret.push_back(i);
cur += Skim(i);
if (cur > A * 2) {
impossible();
return;
}
}
if (cur >= A) answer(ret);
else {
--p;
vector<int> add;
if (p < 0 || p > n) return;
while (p > k && !ret.empty()) {
cur = cur - Skim(ret.back()) + Skim(p);
ret.pop_back();
add.push_back(p);
p--;
if (cur >= A) {
for(int &j : add) ret.push_back(j);
answer(ret);
return;
}
}
impossible();
}
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |