This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "books.h"
#include <bits/stdc++.h>
using namespace std;
int cache[100005];
int n;
int query(int a){
if (cache[a]!=-1) return cache[a];
return cache[a] = skim(a);
}
int find_val(int a, int b, int c = 1, int d = n){
if (query(c)>b) return -(c-1);
if (query(c)>=a) return c;
if (query(d)<a) return -d;
if (query(d)<=b) return d;
while (c+1<d){
int mid = (c+d)/2;
int t = query(mid);
if (a<=t && t<=b) return mid;
if (t<a) c = mid;
else d = mid;
}
return -c;
}
void solve(int N, int K, long long A, int S) {
memset(cache,-1,sizeof(cache));
n = N;
int en = N;
vector<int> extr;
for (int x = K-1; x>=0; x--){
vector<int> ans;
for (int y = 0; y<x; y++){
ans.push_back(y+1);
}
for (auto y : extr) ans.push_back(y);
int sum = 0;
for (auto x : ans){
sum += query(x);
}
int res = find_val(A-sum,2*A-sum,x+1,en);
if (res>0){
ans.push_back(res);
answer(ans);
return;
}
en = -res-1;
if (x>en){
impossible();
}
extr.push_back(-res);
}
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... |