# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
849579 | iee | A Difficult(y) Choice (BOI21_books) | C++17 | 21 ms | 1996 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;
//
// --- 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> av;
for (int i = 1; i <= N; i++) {
av.push_back(i);
}
vector<long long> mem(N + 1, -1);
auto query = [&](int x) {
if (mem[x] != -1) return mem[x];
return mem[x] = skim(x);
};
long long sm = 0;
for (int i = 1; i < K; i++) {
sm += query(i);
}
int l = K, r = N;
while (l < r) {
int mid = (l + r + 1) >> 1;
if (query(mid) + sm <= A * 2) l = mid;
else r = mid - 1;
}
vector<int> p;
for (int i = 1; i < K; i++) {
p.push_back(i);
}
for (int i = l - K + 1; i <= l; i++) {
p.push_back(i);
}
sort(p.begin(), p.end()), p.erase(unique(p.begin(), p.end()), p.end());
for (int s = 0; s < (1 << p.size()); s++) {
if (__builtin_popcount(s) == K) {
long long sum = 0;
vector<int> v;
for (int i = 0; i < p.size(); i++) {
if (s >> i & 1) {
sum += query(p[i]);
v.push_back(p[i]);
}
}
if (sum >= A && sum <= A * 2) {
answer(v);
}
}
}
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... |