이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#include "books.h"
using namespace std;
typedef long long ll;
typedef pair<ll,ll> ii;
//
// --- 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) {
// TODO implement this function
int count=0;
ll b[N+5];
memset(b,0,sizeof(b));
int low = 0, high = N + 1;
while(high - low >= 2)
{
int mid = (high + low) / 2;
count++;
assert(count<S);
b[mid]=skim(mid);
if(b[mid] < A) low = mid;
else high = mid;
}
ll a[K+5];
memset(a,0,sizeof(a));
//cout<<low<<endl;
high=low;
if(high<=K-2)impossible();
for(int i=1; i<=K; i++){
if(!b[i]){
count++;
assert(count<S);
b[i]=skim(i);
}
a[i]=a[i-1]+b[i];
}
ll c[K+5];
memset(c,0, sizeof(c));
for(int i=max(high-K+1,1); i<=high; i++){
if(!b[i]){
count++;
assert(count<S);
b[i]=skim(i);
}
c[i-(high-K)]=c[i-(high-K)-1]+b[i];
}
if(!b[high+1]){
count++;
assert(count<S);
skim(high+1);
}
if(b[high+1]+a[K-1]<2*A){
vector<int> v;
for(int i=1; i<=K-1; i++){
v.push_back(i);
}
v.push_back(high+1);
answer(v);
}else{
for(int i=0; i<K;i++){
//printf("i=%d, sum=%lld \n", i,a[i]+c[K-i]);
if(a[i]+c[K-i]>=A && a[i]+c[K-i]<=2*A){
vector<int> v;
for(int j=1; j<=i; j++){
v.push_back(j);
}
for(int j=0; j<K-i; j++){
v.push_back(high-j);
}
answer(v);
}
}
}
impossible();
}
# | 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... |