# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
657691 | Lobo | A Difficult(y) Choice (BOI21_books) | C++17 | 2 ms | 336 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#include "books.h"
using namespace std;
#define int long long
#define pb push_back
#define mp make_pair
#define fr first
#define sc second
//
// --- 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.
//
const int maxn = 1e5+10;
int n, b[maxn];
int cnt;
int qry(int32_t i) {
if(b[i] == 0) {
// assert(cnt >= 1);
// cnt--;
return b[i] = skim(i);
}
return b[i];
}
void solve(int32_t N, int32_t k, long long A, int32_t S) {
cnt = S;
n = N;
// TODO implement this function
// for(int i = 1; i <= n; i++) {
// // r-l+1 = k -> l = r-k+1
// int r = i;
// int l = r-k+1;
// if(l < 1) continue;
// int sum = 0;
// for(int j = l; j <= r; j++) {
// sum+= qry(j);
// if(sum > 2*A) {
// break;
// }
// }
// if(sum >= A && sum <= 2*A) {
// vector<int32_t> ans;
// for(int j = l; j <= r; j++) {
// ans.pb(j);
// }
// answer(ans);
// return;
// }
// }
cnt-= k-1;
int l = k;
int r = n;
while(l <= r) {
cnt--;
int sum = 0;
int mid = (l+r)/2;
for(int j = 1; j <= k-1; j++) {
sum+= qry(j);
if(sum > 2*A) {
break;
}
}
if(sum+qry(mid) > 2*A) {
r = mid-1;
}
else if(sum+qry(mid) < A) {
l = mid+1;
}
else {
vector<int32_t> ans;
for(int j = 1; j <= k-1; j++) {
ans.pb(j);
}
ans.pb(mid);
answer(ans);
return;
}
}
l = k;
r = n;
int ansbs = -1;
while(l <= r) {
cnt-= k;
int mid = (l+r)/2;
int r1 = mid;
int l1 = r1-k+1;
if(l1 < 1) continue;
int sum = 0;
for(int j = l1; j <= r1; j++) {
sum+= qry(j);
if(sum > 2*A) {
break;
}
}
if(sum > 2*A) {
r = mid-1;
}
else if(sum < A) {
l = mid+1;
}
else {
vector<int32_t> ans;
for(int j = l1; j <= r1; j++) {
ans.pb(j);
}
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... |