# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
247177 | hhh07 | 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 <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <utility>
#include <set>
#include <cmath>
#include <cstring>
#include "prize.h"
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<ll, ll> ii;
int maxi = -1;
vi mem[(int)2e5 + 1];
bool done[(int)2e5 + 1];
vi pitaj(int idx){
if (done[idx])
return mem[idx];
done[idx] = true;
return mem[idx] = ask(idx);
}
int smanji(int x, int y, int t){
while(y > t*x){
vi r = pitaj(y);
if (r[0] + r[1] == 0)
return -y;
if (r[0] + r[1] == maxi)
break;
y--;
}
return y;
}
int bin_search(int lijevo, int beg, int end, int maxi){
if (beg > end)
return -1;
return -1;
int l = beg, r = end;
vi t;
while(l < r){
int mid = (l + r)/2;
t = pitaj(mid);
if (t[0] + t[1] == 0)
return mid;
if (t[0] + t[1] == maxi){
if (lijevo - t[1])
r = mid - 1;
else
l = mid + 1;
}
else
r = mid;
}
l = smanji(end, l, -1);
if (l < 0)
return -l;
if (mem[l][1] - mem[end + 1][1])
return solve(mem[l][1], l + 1, end, maxi);
return -1;
}
int find_best(int n){
memset(done, false, sizeof done);
int maxi, grupa = 460, br = n/460;
int curr = 0;
vi idx;
for (int i = 0; i < grupa; i++){
vi res = pitaj(curr);
maxi = max(maxi, res[0] + res[1]);
if (res[0] + res[1] == 0)
return curr;
idx.push_back(curr);
curr += br;
if (i < n%360)
curr++;
}
done[n] = true; mem[n] = {maxi, 0}; idx.push_back(n);
vi r;
for (int i = 0; i < idx.size() - 1; i++){
int x = idx[i], y = idx[i + 1];
int res = -1;
y = smanji(x, y, 1); x = smanji(y, x, -1);
if (x < 0)
return -x;
if (y < 0)
return -y;
if (x < y)
if (mem[x][1] - mem[y][1])
res = solve(mem[x][1], x + 1, y - 1, maxi);
if ((res + 1))
return res;
}
}