# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
981611 | OAleksa | A Difficult(y) Choice (BOI21_books) | C++14 | 1 ms | 756 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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 - 1, r = lst;
int id = -1;
for (int i = k - 1;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);
}
컴파일 시 표준 에러 (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... |