Submission #1200539

#TimeUsernameProblemLanguageResultExecution timeMemory
1200539PlayVoltzGap (APIO16_gap)C++20
100 / 100
47 ms3260 KiB
#include "gap.h"
#include <bits/stdc++.h>
using namespace std;

#define int long long
#define pii pair<int, int>
#define mp make_pair
#define pb push_back
#define fi first
#define se second

long long findGap(signed t, signed n){
	if (t==1){
		int low=0, high=1e18, ans=0;
		vector<int> vect(n);
		for (int i=0, a, b; i<(n+1)/2; ++i){
			MinMax(low, high, &a, &b);
			vect[i]=a;
			vect[n-1-i]=b;
			low=a+1;
			high=b-1;
		}
		for (int i=1; i<n; ++i)ans=max(ans, vect[i]-vect[i-1]);
		return ans;
	}
	else{
		int low, high, d, ans=0, a, b;
		MinMax(0, 1e18, &low, &high);
		vector<int> vect;
		vect.pb(low);
		vect.pb(high);
		d=(high-low)/n;
		for (int i=low+1; i<high; i+=d+1){
			MinMax(i, i+d, &a, &b);
			if (a==-1)continue;
			vect.pb(a);
			vect.pb(b);
		}
		sort(vect.begin(), vect.end());
		for (int i=1; i<vect.size(); ++i)ans=max(ans, vect[i]-vect[i-1]);
		return ans;
	}
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...