이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "prize.h"
#include <algorithm>
#include <iostream>
#include <chrono>
#include <random>
#include <vector>
using namespace std;
#ifdef MANSON
mt19937 rng(305);
#else
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#endif // MANSON
namespace
{
const int maxN = 200000;
int n;
vector<int> cache[maxN];
inline vector<int> Ask(int i)
{
if (cache[i].size()) return cache[i];
return cache[i] = ask(i);
}
int mx = 0;
inline bool Cheapest(int i)
{
vector<int> res = ask(i);
bool f = (res[0] + res[1] == mx);
// cerr << i << " is" << (f ? " " : "n't ") << " a cheapy.\n";
return f;
}
int Solve(int l, int r)
{
while (l <= r && !Cheapest(l))
{
vector<int> res = Ask(l);
if (res[0] + res[1] == 0) return l;
++l;
}
while (l <= r && !Cheapest(r))
{
vector<int> res = Ask(r);
if (res[0] + res[1] == 0) return r;
--r;
}
if (l >= r) return -1;
vector<int> res1 = Ask(l), res2 = Ask(r);
if (res1[1] == res2[1]) return -1;
int m = (l + r) / 2;
int x = Solve(l, m);
if (x != -1) return x;
return Solve(m + 1, r);
}
}
int find_best(int n_) {
n = n_;
vector<int> p(n);
iota(p.begin(), p.end(), 0);
shuffle(p.begin(), p.end(), rng);
if (p.size() > 500) p.erase(p.begin() + 500, p.end());
for (int i: p)
{
vector<int> res = Ask(i);
mx = max(mx, res[0] + res[1]);
}
return Solve(0, n - 1);
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |