# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
1175439 | mannshah1211 | The Big Prize (IOI17_prize) | C++20 | 0 ms | 0 KiB |
#include "prize.h"
#include <bits/stdc++.h>
using namespace std;
int find_best(int n) {
vector<vector<int>> cache(n, vector<int>(2, -1));
auto uwu = [&](int i) {
if (cache[i] != {-1, -1}) {
return cache[i];
}
return cache[i] = ask(i);
};
int mx = 0, ptr = 0;
while (ptr < n) {
vector<int> v = uwu(ptr);
if (v[0] + v[1] == 0) {
return ptr;
}
if (v[0] == ptr) {
mx = v[0] + v[1];
break;
}
ptr++;
}
while (ptr < n) {
vector<int> v1 = uwu(ptr);
if (v1[0] + v1[1] == mx) {
int low = ptr + 1, high = n - 1, idx = -1;
while (low <= high) {
int mid = (low + high) >> 1;
vector<int> v2 = uwu(mid);
if (v2[1] == v1[1]) {
low = mid + 1;
} else {
idx = mid;
high = mid - 1;
}
}
assert(idx != -1);
ptr = idx + 1;
} else {
ptr += 1;
}
}
}