Submission #395540

#TimeUsernameProblemLanguageResultExecution timeMemory
395540jeroenodbGap (APIO16_gap)C++14
70 / 100
66 ms3248 KiB
#include "gap.h"
#include "bits/stdc++.h"
using namespace std;
#define all(x) begin(x),end(x)
template<typename A, typename B> ostream& operator<<(ostream &os, const pair<A, B> &p) { return os << '(' << p.first << ", " << p.second << ')'; }
template<typename T_container, typename T = typename enable_if<!is_same<T_container, string>::value, typename T_container::value_type>::type> ostream& operator<<(ostream &os, const T_container &v) { string sep; for (const T &x : v) os << sep << x, sep = " "; return os; }
#define debug(a) cerr << "(" << #a << ": " << a << ")\n";
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pi;
typedef pair<ll,ll> pl;
const int mxN = 1e5+1;
const ll oo = 1e18;
long long findGap(int T, int N)
{
	ll amax,amin;
	MinMax(0,oo,&amin,&amax);
	ll ans = (amax-amin+N-2) / (N-1);
	// invariant: low contains a value, range [low+1, low+ans] can't contain answer
	ll low = amin+1;
	vector<pl> groups = {{amin,amin}};
	while(low<amax) {
		ll l,r; MinMax(low,min(amax-1,low+ans),&l,&r);
		low += ans+1;
		if(l==-1) {
			continue;
		}
		groups.push_back({l,r});
		
	}
	groups.push_back({amax,amax});
	for(int i=1;i<(int)groups.size();++i) {
		ans = max(ans, groups[i].first - groups[i-1].second);
	}
	return ans;

}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...