Submission #959564

#TimeUsernameProblemLanguageResultExecution timeMemory
959564MinaRagy06Gap (APIO16_gap)C++17
0 / 100
40 ms4696 KiB
#include <bits/stdc++.h>
#include "gap.h"
#ifdef MINA
#include "grader.cpp"
#endif
using namespace std;
#define ll long long

const ll inf = 1e18;
ll findGap(int t, int n) {
	ll cur, mx;
	MinMax(0, inf, &cur, &mx);
	if (n == 2) {
		return mx - cur;
	}
	if (n == 3) {
		ll s = cur, e = mx;
		ll md;
		MinMax(s + 1, e - 1, &md, &cur);
		return max(md - s, e - md);
	}
	assert(n > 60);
	mx = 1;
	while (cur + mx + 1 < inf) {
		ll len = mx + 1, s = -1, e = -1;
		while (len < inf && e == -1) {
			MinMax(cur + 1, min(cur + len, inf), &s, &e);
			len *= 2;
		}
		if (s != -1) {
			mx = max(mx, s - cur);
		}
		if (e != -1) {
			cur = e;
		} else {
			cur = inf + 1;
		}
	}
	return mx;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...