Submission #1364243

#TimeUsernameProblemLanguageResultExecution timeMemory
1364243jellybeanGap (APIO16_gap)C++20
100 / 100
31 ms3256 KiB
#include "gap.h"
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define pb push_back
#define fi first
#define se second
#define dd(x) cout<<#x<<" is "<<x<<endl;
#define dd2(x,y) cout<<#x<<" is "<<x<<" "<<#y<<" is "<<y<<endl;
typedef pair<int,int> pii;

const int inf = 1e18;
vector<int>nums;

long long findGap(signed T, signed N){
	int mn, mx;
	if(T==1){
		int st = 0, en = inf;
		while(st <= en and nums.size() < N){
			MinMax(st, en, &mn, &mx);
			nums.pb(mn);
			nums.pb(mx);
			st = mn+1, en = mx-1;
		}
	} else {
		MinMax(0, inf, &mn, &mx);
		int x = (mx-mn)/(N-1);
		
		int st = mn, en = mn+x;
		int xx,yy;
		while(en <= mx){
			MinMax(st,en,&xx,&yy);
			if(xx!=-1){
				nums.pb(xx);
				nums.pb(yy);
			}
			st = en+1;
			en = st+x;
		}
		if(st <= mx){
			MinMax(st,mx,&xx,&yy);
			if(xx!=-1){
				nums.pb(xx);
				nums.pb(yy);
			}
		}
	}
	
	sort(nums.begin(), nums.end());
	int ans = 0;
	for(int i=0; i<nums.size()-1; i++) ans = max(ans, nums[i+1]-nums[i]);
	
	return ans;
}
#Result Execution timeMemoryGrader output
Fetching results...
#Result Execution timeMemoryGrader output
Fetching results...