# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
549188 | esomer | The Big Prize (IOI17_prize) | C++17 | 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>
using namespace std;
#define ll long long
vector<int> v;
vector<int> nw;
int a[] = {475, 27, 5, 1};
ll mx;
void bin(int l, int r, int lx, int rx){
if(v.size() == mx) return;
if(l == r){
nw.push_back(v[l]); return;
}
int mid = (l + r) / 2;
vector<int> rep = ask(v[mid]); //
int curr = mid;
while(rep[0] + rep[1] != mx && curr > l){
nw.push_back(v[curr]);
curr--;
rep = ask(v[curr]); //
}
if(rep[0] + rep[1] != mx) nw.push_back(v[curr]);
if(lx + rep[1] < mx && l < curr) bin(l, curr - 1, lx, rep[1]);
curr = mid;
while(rep[0] + rep[1] != mx && curr < r){
nw.push_back(v[curr]);
curr++;
rep = ask(v[curr]); //
}
if(rep[0] + rep[1] != mx) nw.push_back(v[curr]);
if(rx + rep[0] < mx && r > curr) bin(mid + 1, r, rep[0], rx);
}
int find_best(int n) {
v.resize(n);
for(int i = 0; i < n; i++){
v[i] = i;
}
int curr = 0;
int t = 0;
while(v.size() > 1 && t < 1){
mx = 0;
map<int, int> mp;
int lst = 0;
for(int i = 0; i < a[curr] && i < v.size(); i++){
vector<int> rep = ask (v[i]); //
mx = max(mx, rep[0] + rep[1]);
mp[rep[0] + rep[1]]++;
ll sum = mx * mx * mx * mx;
lst = i + 1;
if(rep[0] + rep[1] == 0) return v[i];
if(sum >= n) break;
}
int total = 0;
for(auto p : mp){
if(p.first == mx) break;
total += p.second;
}
bin(lst, v.size() - 1, total, 0);
curr++;
v = nw;
sort(v.begin(), v.end());
nw.clear();
t++;
}
for(int x : v){
vector<int> rep = ask(x);
if(rep[0] + rep[1] == 0) return x;
}
}