제출 #1029837

#제출 시각아이디문제언어결과실행 시간메모리
1029837stdfloatGap (APIO16_gap)C++17
89.04 / 100
38 ms1248 KiB
#include <bits/stdc++.h>
#include "gap.h"
// #include "grader.cpp"
using namespace std;

using ll = long long;

ll findGap(int T, int n) {
	if (T == 1) {
		ll s, t;
		MinMax(0, (ll)1e18, &s, &t);
	
		int cnt = 1;
		ll ans = 0;
		while (++cnt <= ((n + 1) >> 1) && s + 1 < t) {
			ll x, y;
			MinMax(s + 1, t - 1, &x, &y);
	
			if (x == -1) break;
		
			ans = max({ans, x - s, t - y});
			s = x; t = y;
		}
	
		return max(ans, t - s);
	}

	ll s, t;
	MinMax(0, (ll)1e18, &s, &t);

	ll d = (t - s - 1) / (n - 1), mx = 0, a = s;
	while (s + 1 < t) {
		ll x, y;
		MinMax(s + 1, min(s + d, t - 1), &x, &y);

		if (x != -1) {
			mx = max(mx, x - a); a = y;
		}

		s += d;
	}

	return max(mx, t - a);
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...