Submission #649098

#TimeUsernameProblemLanguageResultExecution timeMemory
649098ymmThe Big Prize (IOI17_prize)C++17
97.41 / 100
55 ms368 KiB
#include "prize.h"
#include <bits/stdc++.h>
#define Loop(x,l,r) for (ll x = (l); x < (ll)(r); ++x)
#define LoopR(x,l,r) for (ll x = (r)-1; x >= (ll)(l); --x)
typedef long long ll;
typedef std::pair<int, int> pii;
typedef std::pair<ll , ll > pll;
using namespace std;

jmp_buf ret_env;
int ret_val;
auto ret_ask(int i)
{
	auto v = ask(i);
	if (v[0] + v[1] == 0) {
		ret_val = i;
		longjmp(ret_env, 1);
	}
	return v;
}

const int N = 200'010;
int cnt_expen = 0;

void solve(int l, int r, int cntl, int cnt, int cntr)
{
	if (cnt == 0 || l >= r)
		return;
	int ml = (l+r)/2, mr = (l+r)/2;
	vector<int> lst;
	int lstd;
	while (l < ml || mr < r) {
		if (mr < r) {
			lstd = 1;
			lst = ret_ask(mr++);
			if (lst[0] + lst[1] == cnt_expen)
				break;
		}
		if (l < ml) {
			lstd = 0;
			lst = ret_ask(--ml);
			if (lst[0] + lst[1] == cnt_expen)
				break;
		}
	}
	if (l == ml && r == mr)
		return;
	int to_l = lstd == 1? mr-ml-1: 0;
	int to_r = lstd == 0? mr-ml-1: 0;
	solve(l, ml, cntl, lst[0] - cntl - to_l, lst[1] + to_l);
	solve(mr, r, lst[0] + to_r, lst[1] - cntr - to_r, cntr);
}

int find_best(int n)
{
	if (setjmp(ret_env))
		return ret_val;
	if (n <= 5000) {
		Loop (i,0,n)
			ret_ask(i);
	}
	int cnt_this = 0;
	int cnt_pre = 0;
	Loop (i,0,500) {
		auto tmp = ret_ask(i);
		int x = tmp[0] + tmp[1];
		if (x > cnt_expen) {
			cnt_pre += cnt_this;
			cnt_this = 0;
			cnt_expen = x;
		}
		if (x == cnt_expen)
			cnt_this++;
	}
	solve(500, n, cnt_pre, cnt_expen - cnt_pre, 0);
}

Compilation message (stderr)

prize.cpp: In function 'int find_best(int)':
prize.cpp:76:1: warning: control reaches end of non-void function [-Wreturn-type]
   76 | }
      | ^
prize.cpp: In function 'void solve(int, int, int, int, int)':
prize.cpp:48:22: warning: 'lstd' may be used uninitialized in this function [-Wmaybe-uninitialized]
   48 |  int to_l = lstd == 1? mr-ml-1: 0;
      |             ~~~~~~~~~^~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...