제출 #953933

#제출 시각아이디문제언어결과실행 시간메모리
9539334QT0RGap (APIO16_gap)C++17
100 / 100
46 ms3328 KiB
#include <bits/stdc++.h>
#include "gap.h"
using namespace std;
#define ll long long

ll findGap(int T, int n){
	ll L,P;
	MinMax(0,1e18,&L,&P);
	ll d=(P-L+n-2)/(n-1);
	ll ans=d,x,y;
	if (T==1){
		for (ll i = 1; i<(n+1)/2; i++){
			if (L+1==P)break;
			MinMax(L+1,P-1,&x,&y);
			if (x==-1){
				ans=max(ans,P-L);
				break;
			}
			else ans=max({ans,x-L,P-y});
			L=x;
			P=y;
		}
	}
	else{
		ll iter,l=L;
		for (iter = L; iter+d<P; iter+=d+1){
			MinMax(iter,iter+d,&x,&y);
			if (x!=-1){
				ans=max(ans,x-l);
				l=y;
			}
		}
		MinMax(iter,P,&x,&y);
		if (x!=-1){
			ans=max(ans,x-l);
		}
	}
	return ans;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...