# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
136101 | JustasZ | The Big Prize (IOI17_prize) | C++14 | 0 ms | 0 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "prize.h"
#include <bits/stdc++.h>
#define pb push_back
#define all(a) a.begin(), a.end()
#define sz(a) (int)a.size()
#define x first
#define y second
#define debug(...) cout << "[" << #__VA_ARGS__ << ": " << __VA_ARGS__ << "]\n"
#define rd() abs((int)rng())
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int>pii;
const int maxn = 2e5 + 100;
const int mod = 1e9 + 7;
mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
vector<int> ask(int i)
{
cout << "? " << i << endl;
vector<int>a(2);
cin >> a[0] >> a[1];
return a;
}
map<int, vector<int> >mp;
vector<int> askk(int i)
{
if(!mp.count(i))
mp[i] = ask(i);
return mp[i];
}
int bl = 265;
int find_best(int n)
{
vector<int>a, b;
int mx = 3;
/*for(int i = 0; i < min(n, 500); i++)
{
a = askk(i);
if(a[0] + a[1] == 0)
return i;
mx = max(mx, a[0] + a[1]);
}*/
for(int i = 0; i < n; i += bl)
{
int j = min(i + bl - 1, n - 1);
int p = i;
a = askk(p);
while(a[0] + a[1] != mx)
{
if(a[0] + a[1] == 0)
return p;
p++;
if(p > j)
break;
a = askk(p);
}
b = askk(j);
while(b[0] + b[1] != mx)
{
if(b[0] + b[1] == 0)
return j;
j--;
if(j < p)
break;
b = askk(j);
}
if(p < j)
{
int between = b[0] - a[0];
if(between != 0)
{
for(int c = 1; c <= between; c++)
{
int l = p + 1, r = j - 1;
while(l < r)
{
int mid = (l + r + 1) / 2;
b = askk(mid);
if(b[0] - a[0] > c)
r = mid - 1;
else
l = mid;
}
b = askk(l);
if(b[0] + b[1] == 0)
return l;
}
}
}
}
}