#include "prize.h"
#include <bits/stdc++.h>
using namespace std;
map<int, pair<int, int> > asked;
vector<int> pos;
int left_val(int x) {
if (!asked.count(x)) {
vector<int> tmp = ask(x);
asked[x] = make_pair(tmp[0], tmp[1]);
}
return asked[x].first;
}
int right_val(int x) {
if (!asked.count(x)) {
vector<int> tmp = ask(x);
asked[x] = make_pair(tmp[0], tmp[1]);
}
return asked[x].second;
}
void find_pos(int l, int r, int nPos) {
if (l>r)
return;
int mid = (l + r) / 2;
int tmp = mid;
for (; mid>=l; --mid) {
if (left_val(mid)+right_val(mid)==nPos)
break;
pos.push_back(mid);
}
find_pos(l, mid-1, left_val(mid));
find_pos(tmp+1, r, right_val(mid)-(tmp-mid));
}
int find_best(int n) {
int l = 0;
while (l<n && n-left_val(l)-right_val(l)!=0) {
pos.push_back(l);
++l;
}
if (l<n)
find_pos(l, n-1, right_val(l));
for (auto v : pos) {
if (left_val(v) + right_val(v) == 0)
return v;
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
70 ms |
920 KB |
Incorrect |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
61 ms |
952 KB |
Incorrect |
2 |
Halted |
0 ms |
0 KB |
- |