Submission #792590

#TimeUsernameProblemLanguageResultExecution timeMemory
792590IvanJGap (APIO16_gap)C++17
70 / 100
44 ms2248 KiB
#include "gap.h"
#include<bits/stdc++.h>

#define pb push_back
#define x first
#define y second
#define all(a) (a).begin(), (a).end()

using namespace std;

typedef long long ll;
typedef pair<int, int> ii;

ll findGap(int T, int N) {
	if(T == 1) {
		ll lo = 0, hi = 1e18, mini = 0;
		vector<ll> a;
		int sz = N;
		while(hi - lo >= mini) {
			MinMax(lo, hi, &lo, &hi);
			mini = max(mini, (hi - lo) / ((ll)sz - 1));
			a.pb(lo), a.pb(hi);
			sz -= 2;
			if(lo == hi) sz++;
			lo++, hi--;
		}
		sort(all(a));
		ll ans = 0;
		for(int i = 1;i < (int)a.size();i++)
			ans = max(ans, a[i] - a[i - 1]);
		return ans;
	}
	if(T == 2) {
		ll lo = 0, hi = 1e18;
		MinMax(lo, hi, &lo, &hi);
		ll min_gap = (hi - lo) / ((ll)N - 1);
	
		ll ans = 0;
		ll x = lo + 1, lst = lo, l, r;
		while(x < hi) {
			MinMax(x, x + min_gap, &l, &r);
			if(l != -1) 
				ans = max(ans, l - lst);
			x += min_gap + 1;
			if(r != -1) lst = r;
		}
		if(x == hi) ans = max(ans, hi - lst);
		return ans;
	}
}

Compilation message (stderr)

gap.cpp: In function 'll findGap(int, int)':
gap.cpp:50:1: warning: control reaches end of non-void function [-Wreturn-type]
   50 | }
      | ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...