Submission #982275

#TimeUsernameProblemLanguageResultExecution timeMemory
982275CBCodeGap (APIO16_gap)C++17
30 / 100
47 ms4100 KiB
#include "gap.h"
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
ll findGap(int T, int N) {
	if(T==1) {
		vector<ll> a(N);
		int l = 0, r = N-1;
		ll mnn = 0, mxx = 1e18;
		while(l <= r) {
			MinMax(mnn, mxx, &a[l], &a[r]);
			mnn = a[l]+1; mxx = a[r]-1;
			l++; r--;
		}
		ll ans = 0;
		for(int i = 1; i < N; i++) {
			ans = max(ans, a[i]-a[i-1]);
		}
		return ans;
	}
	else {
		ll mnn, mxx, premx;
		MinMax(0, 1e18, &mnn, &mxx);
		premx = mnn;
		const ll MX = mxx;
		ll minGap,ans; minGap = ans = (ll)ceil((long double)(mxx-mnn)/(N-1));
		ll s;
		//cout <<minGap<<endl;
		for(s = mnn+1; s < MX; s+=minGap) {
			MinMax(s, s+minGap, &mnn, &mxx);
			//cout << s << " " << mnn << " " << mxx << ' '<<premx<<endl;
			ans = max(ans, mnn-premx);
			premx = mxx;
			//cout << s+minGap << ' '<<mxx<<endl;
		}
		ans = max(ans, mxx-premx);
		return ans;
	}
	return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...