이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
//by szh
#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define pii pair<int,int>
#define pll pair<long long,long long>
#define pb push_back
#define debug(x) cerr<<#x<<"="<<x<<endl
#define pq priority_queue
#define inf 0x3f
#define rep(i,a,b) for (int i=a;i<(b);i++)
#define MP make_pair
#define SZ(x) (int(x.size()))
#define mod 1000000007
typedef long long ll;
#define ALL(x) x.begin(),x.end()
void inc(int &a,int b) {a=(a+b)%mod;}
void dec(int &a,int b) {a=(a-b+mod)%mod;}
int lowbit(int x) {return x&(-x);}
ll p0w(ll base,ll p) {ll ret=1;while(p>0){if (p%2ll==1ll) ret=ret*base%mod;base=base*base%mod;p/=2ll;}return ret;}
#include "books.h"
const int maxn = 1e5+10;
ll dif[maxn];
ll AA;
int KK;
ll check(int pos) {
ll ret = 0;
rep(i,pos-KK+1,pos+1) {
if (dif[i]==-1) dif[i] = skim(i);
ret += dif[i];
ret = min(ret,2*AA+319);
if ((pos-i)*dif[i] > 2*AA or ret + (pos-i)*dif[i] > 2*AA) return 2*AA+319;
}
return ret;
}
void solve(int N, int K, long long A, int S) {
AA = A; KK = K;
memset(dif,-1,sizeof(dif));
// TODO implement this function
if (S==N) {
rep(i,1,N+1) dif[i] = skim(i);
ll sum = 0;
rep(i,1,K+1) {
sum += dif[i];
if (sum>2*A) impossible();
}
vector <int> ret;
if (sum>=A) {
rep(i,1,K+1) ret.pb(i);
answer(ret);
}
rep(i,K+1,N+1) {
sum += dif[i];
sum -= dif[i-K];
if (sum>2*A) {
if (dif[i]>2*A) impossible();
ll sum1 = 0;
rep(j,1,K) ret.pb(j),sum1 += dif[j];
ret.pb(i);sum1+=dif[i];
if (sum1<=2*A) answer(ret);
impossible();
}
if (sum>=A) {
rep(j,i-K+1,i+1) ret.pb(j);
answer(ret);
}
}
impossible();
}
ll sum = 0;vector <int> ret;
rep(i,1,K) dif[i] = skim(i), sum += dif[i];
if (sum>2*A) impossible();
int l = K, r = N;
while (l<r) {
int mid=l+r+1>>1;
dif[mid] = skim(mid);
if (sum+dif[mid]>2*A) r = mid-1;
else l = mid;
}
if (dif[l]==-1) dif[l] = skim(l);
if (sum+dif[l]>2*A) impossible();
if (sum+dif[l]>=A) {
rep(i,1,K) ret.pb(i);
ret.pb(l);
answer(ret);
}
sum += dif[l];
int tmpl = 1, tmpr = l-1;
while (tmpl<K) {
if (dif[tmpr]==-1) dif[tmpr] = skim(tmpr);
sum = sum - dif[tmpl] + dif[tmpr];
tmpl++,tmpr--;
assert(sum<=2*A);
if (sum>=A) {
rep(i,tmpl,K) ret.pb(i);
rep(i,tmpr+1,l+1) ret.pb(i);
answer(ret);
}
}
impossible();
}
컴파일 시 표준 에러 (stderr) 메시지
books.cpp: In function 'void solve(int, int, long long int, int)':
books.cpp:81:14: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
81 | int mid=l+r+1>>1;
| ~~~^~
# | 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... |