#include "prize.h"
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define INF (1 << 30)
#define MOD (1000 * 1000 * 1000 + 7)
#define maxn 201111
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
bool used[maxn];
vector<int> v[maxn];
set<pii> s[maxn];
int ans;
pii ASK(int x){
if(!used[x]){
v[x] = ask(x);
used[x] = 1;
}
return mp(v[x][0], v[x][1]);
}
void solve(int l, int d){
if(ans != -1 || l > d)
return;
int mid = (l + d) / 2;
pii cur = ASK(mid);
int sum = cur.fi + cur.se;
if(sum == 0){
ans = mid;
return;
}
auto it = s[sum].upper_bound(cur);
bool left = 1, right = 1;
if(it != s[sum].begin()){
it--;
if(it -> se - cur.se == 0)
left = 0;
it++;
}
if(it != s[sum].end()){
it--;
if(cur.se - it -> se == 0)
right = 0;
}
s[sum].insert(cur);
if(left)
solve(l, mid - 1);
if(right)
solve(mid + 1, d);
}
int find_best(int n){
ans = -1;
solve(0, n - 1);
return ans;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
17 ms |
14584 KB |
Integer -1 violates the range [0, 199999] |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
15 ms |
14584 KB |
Integer -1 violates the range [0, 199999] |
2 |
Halted |
0 ms |
0 KB |
- |