이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#include "books.h"
using namespace std;
typedef long long ll;
const int mxN=100010;
//
// --- 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.
//
ll N, K, lim;
ll A[mxN];
int cursor;
bool f1()
{
A[N]=skim(N);
for(int i=1;i<=K;i++) A[i]=skim(i);
if(A[N]<lim)
{
cursor=N+1;
return false;
}
int s=1, e=N;
while(s!=e)
{
int mid=(s+e)/2;
if(skim(mid)>=lim) e=mid;
else s=mid+1;
}
cursor=e;
A[cursor]=skim(cursor);
if(cursor<K) return false;
ll sum=0;
for(int i=1;i<K;i++) sum+=A[i];
sum+=A[cursor];
if(sum<=2*lim)
{
vector <int> v;
for(int i=1;i<K;i++) v.push_back(i);
v.push_back(cursor);
answer(v);
return true;
}
return false;
}
bool f2()
{
if(cursor<=K) return false;
ll sum=0;
for(int i=1;i<=K;i++) sum+=A[i];
if(sum>2*lim) return false;
if(sum>=lim)
{
vector <int> v;
for(int i=1;i<=K;i++) v.push_back(i);
answer(v);
return true;
}
for(int i=cursor-K;i<=cursor-1;i++) A[i]=skim(i);
for(int i=K;i>=1;i--)
{
sum-=A[i];
sum+=A[cursor-K-1+i];
if(sum>=lim)
{
vector <int> v;
for(int j=1;j<i;j++) v.push_back(j);
for(int j=i;j<=K;j++) v.push_back(cursor-K-1+j);
answer(v);
return true;
}
}
return false;
}
void solve(int n, int k, long long a, int S) {
// TODO implement this function
N=n, K=k, lim=a;
bool ok=f1();
if(!ok) ok=f2();
if(!ok) 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... |