이 제출은 이전 버전의 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
#define all(x) x.begin(),x.end()
const int maxn = 1e5+10;
const int maxv = 2e18+10;
int n, b[maxn];
int cnt;
int qry(int32_t i) {
if(b[i] == 0) {
assert(cnt--);
return b[i] = skim(i);
}
return b[i];
}
int qrysum(int l, int r) {
int sum = 0;
for(int i = l; i <= r; i++) {
sum+= qry(i);
sum = min(sum,maxv);
}
return sum;
}
void solve(int32_t N, int32_t k, long long A, int32_t S) {
cnt = 50;
n = N;
int l,r;
l = 1;
r = n;
int p = -1;
while(l <= r) {
int mid = (l+r)/2;
if(qry(mid) >= A) {
r = mid-1;
p = mid;
}
else {
l = mid+1;
}
}
if(p != -1) {
if(p < k) {
impossible();
return;
}
if(qrysum(1,k-1)+qry(p) <= 2*A) {
vector<int32_t> ans;
for(int j = 1; j <= k-1; j++) ans.pb(j);
ans.pb(p);
answer(ans);
return;
}
if(p == k) {
impossible();
return;
}
n = p-1;
// n is >= k
}
int sumcur = qrysum(1,k);
if(sumcur > 2*A) {
impossible();
return;
}
if(sumcur >= A) {
vector<int32_t> ans;
for(int j = 1; j <= k; j++) ans.pb(j);
answer(ans);
return;
}
vector<int32_t> ans;
for(int i = k; i >= 1; i--) {
if(sumcur-qry(i)+qry(n) < A) {
sumcur = sumcur-qry(i)+qry(n);
ans.pb(n);
n--;
}
else if(sumcur-qry(i)+qry(n) <= 2*A) {
//I found the answer
ans.pb(n);
for(int j = 1; j < i; j++) ans.pb(j);
sort(all(ans));
answer(ans);
return;
}
}
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... |