Submission #785696

#TimeUsernameProblemLanguageResultExecution timeMemory
785696QwertyPiThe Big Prize (IOI17_prize)C++14
93.13 / 100
52 ms1052 KiB
#include "prize.h"
#include <bits/stdc++.h>

using namespace std;

map<int, vector<int>> M, Li;
vector<int> self_ask(int i){
	if(!M.count(i)) M[i] = ask(i); vector<int> r = M[i];
	Li[r[0] + r[1]].push_back(i);
	return r;
}

vector<int> b;

void solve(int l, int r, int cc, int lc, int rc){
	if(l > r || lc == rc) return;
	int L = (l + r) / 2, R = (l + r) / 2 + 1, F = 0;
	int c; vector<int> a;
	while(true){
		c = F ? R++ : L--; F ^= 1;
		a = self_ask(c);
		if(a[0] + a[1] == cc || R - L - 1 == rc - lc){
			break;
		}
	}
	if(c == L + 1){
		solve(l, L, cc, lc, a[0]);
		solve(R, r, cc, a[0] + (R - L - 2), rc);
	}else{
		solve(l, L, cc, lc, a[0] - (R - L - 2));
		solve(R, r, cc, a[0], rc);
	}
}

int find_best(int n) {
	
	for(int i = max(0, n / 2 - 250); i < min(n, n / 2 + 250); i++) self_ask(i);
	int cc = (--Li.end())->first;
	solve(0, n - 1, cc, 0, cc);
	for(auto [i, p] : M){
		if(p[0] + p[1] == 0){
			return i;
		}
	}
	return -1; 
}

Compilation message (stderr)

prize.cpp: In function 'std::vector<int> self_ask(int)':
prize.cpp:8:2: warning: this 'if' clause does not guard... [-Wmisleading-indentation]
    8 |  if(!M.count(i)) M[i] = ask(i); vector<int> r = M[i];
      |  ^~
prize.cpp:8:33: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'if'
    8 |  if(!M.count(i)) M[i] = ask(i); vector<int> r = M[i];
      |                                 ^~~~~~
prize.cpp: In function 'int find_best(int)':
prize.cpp:40:11: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   40 |  for(auto [i, p] : M){
      |           ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...