이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pi;
typedef pair<ll,ll> pl;
#define endl '\n'
#define F first
#define S second
#define all(x) (x).begin(),(x).end()
const int N = 3e5+1;
const ll INF = 2e18;
const int MOD = 1e9+7;
vector<int> ask(int i);
vector<vector<int> > memo(N);
const int block = 5;
int nn;
int queried = 0;
set<int> sums;
vector<int> askme(int i){
if(memo[i].empty()){
queried++;
assert(queried <= 10000);
memo[i] = ask(i);
assert(sums.count(memo[i][0] + memo[i][1]));
}
return memo[i];
}
int seen,cheap;
int go(int b){
for(int i=b*block;i<min(nn,(b+1)*block);i++){
vector<int> arr = askme(i);
if(arr[0] + arr[1] == 0)
return i;
if(arr[0] + arr[1] < cheap)
seen++;
}
return -1;
}
int find_best(int n) {
/// the second to smallest price is in at most 450 boxes
/// the maximum amount of prizes is 5
nn = n;
int blocks = (n+4)/5;
for(int i=0;i<min(500,blocks);i++){
vector<int> arr = askme(i*block);
cheap = max(cheap,arr[0] + arr[1]);
sums.insert(arr[0] + arr[1]);
}
int L = 0,R = blocks-1;
while(L<=R){
int l = L,r = R;
while(l<=r){
int mid = (l+r)/2;
int low,high,pos;
pos = mid*block;
vector<int> arr = askme(pos);
low = arr[0],high = arr[1];
if(low + high == 0)
return pos;
if(low + high < cheap){
bool chk = 0;
if(mid != 0){
vector<int> arr = askme(pos-1);
if(arr[0] + arr[1] < cheap || arr[0] - seen > 0)
chk = 1;
if(arr[0] + arr[1] == 0)
return pos-1;
}
if(chk){
r = mid-1;
}
else{
r = mid;
l = mid+1;
}
continue;
}
if(low - seen > 0)
r = mid-1;
else
l = mid+1;
}
int ans = go(r);
if(ans != -1)
return ans;
L = r+1;
}
}
컴파일 시 표준 에러 (stderr) 메시지
prize.cpp: In function 'int find_best(int)':
prize.cpp:105:1: warning: control reaches end of non-void function [-Wreturn-type]
105 | }
| ^
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |