# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
499572 | aryan12 | A Difficult(y) Choice (BOI21_books) | C++17 | 1 ms | 264 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) {
long long L = 1, R = N;
long long omk = 0;
while(L <= R) {
long long mid = (L + R) >> 1;
long long val = skim(mid);
if(val <= A) {
L = mid + 1;
omk = mid;
}
else {
R = mid - 1;
}
}
//cout << "omk = " << omk << "\n";
if(omk != N) {
omk++;
}
if(omk <= K) {
vector<int> val;
int sum = 0;
for(int i = 1; i <= K; i++) {
int hii = skim(i);
val.push_back(i);
sum += hii;
}
if(sum > 2 * A || sum < A) {
impossible();
}
else {
answer(val);
}
return;
}
vector<pair<int, int> > val;
set<int> hoho;
for(int i = 1; i <= K; i++) {
int value = skim(i);
val.push_back({i, value});
hoho.insert(i);
}
for(int i = omk; i > omk - K; i--) {
if(!hoho.count(i)) {
int value = skim(i);
val.push_back({i, value});
hoho.insert(i);
}
}
vector<int> ans;
int newn = val.size();
int pref[newn], suf[newn];
for(int i = 0; i < newn; i++) {
pref[i] = 0;
suf[i] = 0;
}
pref[0] = val[0].second;
suf[newn - 1] = val[newn - 1].second;
for(int i = 1; i < val.size(); i++) {
pref[i] = pref[i - 1] + val[i].second;
}
for(int i = val.size() - 2; i >= 0; i--) {
suf[i] = suf[i + 1] + val[i].second;
}
int cur_ans = 0;
for(int i = newn - 1; i > newn - 1 - K; i--) {
cur_ans += val[i].second;
}
if(cur_ans < A) {
impossible();
return;
}
if(cur_ans <= 2 * A) {
for(int i = newn - K; i < newn; i++) {
ans.push_back(val[i].first);
}
answer(ans);
return;
}
int pos = newn - 1;
for(int i = 1; i <= K; i++) {
cur_ans -= val[pos--].second;
cur_ans += val[i].second;
if(cur_ans <= 2 * A) {
assert(cur_ans >= A);
for(int j = 1; j <= i; j++) {
ans.push_back(val[j].first);
}
for(int j = newn - K; j <= pos; j++) {
ans.push_back(val[j].first);
}
answer(ans);
return;
}
}
impossible();
}
컴파일 시 표준 에러 (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... |