Submission #1104426

#TimeUsernameProblemLanguageResultExecution timeMemory
1104426codexistentGap (APIO16_gap)C++14
100 / 100
46 ms5828 KiB

// testing, nmc
#include "gap.h"
#include<bits/stdc++.h>
using namespace std;
#define ll long long
 
long long findGap(int T, int N) {
	if (T == 1) {
		vector<ll> a;
		auto calc = [&](auto self, ll l, ll r) -> void {
			if (l > r || (int)a.size() == N) return;
			ll x, y;
			MinMax(l, r, &x, &y);
			if (x != -1)
				a.push_back(x);
			if (y != x)
				a.push_back(y);
			self(self, x + 1, y - 1);
			};
		calc(calc, 0, 1e18);
		sort(a.begin(), a.end());
		ll res = a[1] - a[0];
		for (int i = 2; i < N; ++i)
			res = max(res, a[i] - a[i - 1]);
		return res;
	}
 
	ll mn, mx;
	MinMax(1, 1e18, &mn, &mx);
	ll step = (mx - mn) / (N - 1);
	ll ans = step, x, y, l = mn, i;
	for (i = mn; i + step < mx; i += step + 1) {
		MinMax(i, i + step, &x, &y);
		if (x != -1) {
			ans = max(ans, x - l);
			l = y;
		}
	}
	MinMax(i, mx, &x, &y);
	if (x != -1) ans = max(ans, x - l);
	return ans;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...