이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "prize.h"
#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> ii;
int find_best(int n) {
if (n < 5000) {
for (int i = 0; i < n; ++i) {
auto a = ask(i);
if (a[0] + a[1] == 0) return i;
}
}
int large = 0;
vector<int> val(450);
for (int i = 0; i < 450; ++i) {
auto a = ask(i);
val[i] = a[0] + a[1];
if (val[i] == 0) return i;
large = max(large, val[i]);
}
int found = 0;
for (int a : val) if (a != large) found++;
int low = 450;
for (int i = found + 1; i <= large; ++i) {
int upp = n - 1;
while (low < upp) {
int mid = (low + upp) / 2;
auto a = ask(mid);
int tot = a[0] + a[1];
if (tot == 0) return mid;
if (tot < large) {
int skip = 0;
while (tot < large) {
mid--;
skip++;
a = ask(mid);
tot = a[0] + a[1];
if (tot == 0) return mid;
}
if (a[0] + skip >= i) low = upp = mid + i - a[0];
}
if (a[0] < i) low = mid + 1;
else upp = mid - 1;
}
auto a = ask(low);
if (a[0] + a[1] == 0) return low;
low++;
}
return -1;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |