이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "prize.h"
#include <bits/stdc++.h>
using namespace std;
pair<int,int> memo[200005];
pair<int,int> qry(int x){
if(memo[x].first!=-1)return memo[x];
vector<int> v=ask(x);
return memo[x]=make_pair(v[0],v[1]);
}
int find_best(int n){
for(int i=0;i<n;i++)memo[i]=make_pair(-1,-1);
int k=1;
while(k*(k+1)<n)k++;
int sz=0;
for(int i=0;i<k;i++){
pair<int,int> p=qry(i);
sz=max(sz,p.first+p.second);
}
for(int start=0;start<k;start++){
pair<int,int> p=qry(start);
if(p.first+p.second==sz){
int ans=start;
while(ans<n){
p=qry(ans);
if(p.first+p.second==sz){
int l=ans,r=n-1; // rightmost thing with the same p
pair<int,int> p2;
while(l<r){
int mid=(l+r+1)/2;
p2=qry(mid);
if(p2==p){
l=mid;
}else{
r=mid-1;
}
}
ans=l+1;
}else{
if(p.first==0&&p.second==0)break;
ans++;
}
}
return ans;
}else if(p.first==0&&p.second==0){
return start;
}
}
return n;
}
/*
8
3 2 3 1 3 3 2 3
*/
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |