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 "prize.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int MAXN = 2e5;
int N;
pii M[MAXN+10];
pii query(int x)
{
if(M[x]!=pii(-1, -1)) return M[x];
vector<int> res=ask(x-1);
return M[x]=pii(res[0], res[1]);
}
int find_best(int _N)
{
N=_N;
for(int i=1; i<=N; i++) M[i]=pii(-1, -1);
int t=0;
for(int i=1; i<=min(720, N); i++)
{
pii p=query(i);
t=max(t, p.first+p.second);
}
for(int i=1; i<=N;)
{
pii p=query(i);
if(p.first==0 && p.second==0) return i-1;
if(p.first+p.second==t)
{
int lo=i, hi=N+1;
while(lo+1<hi)
{
int mid=lo+hi>>1;
if(query(mid).second==p.second) lo=mid;
else hi=mid;
}
i=hi;
}
else
{
i++;
}
}
}
Compilation message (stderr)
prize.cpp: In function 'int find_best(int)':
prize.cpp:42:15: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
42 | int mid=lo+hi>>1;
| ~~^~~
prize.cpp:53:1: warning: control reaches end of non-void function [-Wreturn-type]
53 | }
| ^
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |