# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
525906 | Qingyu | A Difficult(y) Choice (BOI21_books) | C++17 | 2 ms | 1092 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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) {
auto ok = [&](long long x) -> bool {
return A <= x && x <= 2 * A;
};
vector<long long> X(N + 1, -1);
auto get = [&](int k) -> long long {
if (X[k] == -1) X[k] = skim(k);
return X[k];
};
long long total = 0;
for (int i = 1; i <= K; ++i) {
total += get(i);
}
if (total > 2 * A) {
impossible();
return;
}
if (total >= A) {
vector<int> v;
for (int i = 1; i <= K; ++i) v.push_back(i);
answer(v);
return;
}
int l = K, r = N, ans = -1;
while (l <= r) {
const int mid = l + r >> 1;
if (X[mid] == -1) X[mid] = skim(mid);
if (X[mid] < A) ans = mid, l = mid + 1;
else r = mid - 1;
}
if (ans < N) {
total = 0;
for (int i = 1; i < K; ++i) total += get(i);
total += get(ans + 1);
assert(total >= A);
if (total <= 2 * A) {
vector<int> v;
for (int i = 1; i < K; ++i) v.push_back(i);
v.push_back(ans + 1);
answer(v);
return;
}
}
if (ans - K + 1 <= K) {
for (int j = K + 1; j <= ans; ++j)
X[j] = skim(j);
auto Y = X;
for (int i = 1; i <= ans; ++i) Y[i] += Y[i - 1];
for (int i = K; i <= ans; ++i)
if (ok(Y[i] - Y[i - K])) {
vector<int> v;
for (int j = i - K + 1; j <= i; ++j)
v.push_back(j);
answer(v);
return;
}
impossible();
return;
}
for (int i = ans - K + 1; i <= ans; ++i)
if (X[i] == -1)
X[i] = skim(i);
total = 0;
for (int i = 1; i <= K; ++i) total += X[i];
for (int j = 1; j <= K; ++j) {
total -= X[j];
total += X[ans - K + j];
if (ok(total)) {
vector<int> v;
for (int t = j + 1; t <= K; ++t) v.push_back(t);
for (int t = 1; t <= j; ++t)
v.push_back(ans - K + t);
answer(v);
return;
}
}
impossible();
return;
}
컴파일 시 표준 에러 (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... |