이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <iostream>
#include <vector>
using namespace std;
#include "books.h"
int findA(vector<long long>& books, long long A, int lower, int upper) {
if (books[lower] == -1) {
books[lower] = skim(lower + 1);
}
if (books[upper] == -1) {
books[upper] = skim(upper + 1);
}
if (books[lower] > A) {
return lower;
}
if (books[upper] < A) {
return -1;
}
if (upper - lower < 2) {
return upper;
}
int half = (upper - lower + 1) / 2;
books[lower + half] = skim(lower + half + 1);
if (books[lower + half] < A) return findA(books, A, lower + half, upper);
else return findA(books, A, lower, lower + half);
}
void solve(int N, int K, long long A, int S) {
if (K > N) {
impossible();
return;
}
vector<long long> books(N);
for (int i = 0; i < N; i++) {
books[i] = -1;
}
long long sumFirstK = 0;
for (int i = 0; i < K; i++) {
if (books[i] == -1) {
books[i] = skim(i + 1);
}
sumFirstK += books[i];
}
if (sumFirstK > A * 2) {
impossible();
}
else {
vector<int> res;
for (int i = 0; i < K; i++) {
res.push_back(i + 1);
}
if (sumFirstK >= A) {
answer(res);
}
else {
// sumFirstK < A
long long posA = findA(books, A, 0, N - 1);
if (posA != -1) {
res[K-1] = posA + 1;
answer(res);
}
else {
// all elements < A and the sum of first k is < A
// sample last k
for (int i = 0; i < K; i++) {
if (books[N - 1 - i] == -1) {
books[N - 1 - i] = skim(N - i);
}
sumFirstK -= books[i];
res[i] = N - i;
sumFirstK += books[N - 1 - i];
if (sumFirstK >= A) {
answer(res);
break;
}
}
impossible();
}
}
}
return;
}
# | 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... |