제출 #1196462

#제출 시각아이디문제언어결과실행 시간메모리
1196462The_SamuraiGap (APIO16_gap)C++20
30 / 100
44 ms1864 KiB
#include "bits/stdc++.h"
#include "gap.h"
using namespace std;
using ll = long long;

long long findGap(int t, int n) {
	if (t == 1) {
		vector<ll> a(n);
		int l = 0, r = n - 1;
		ll lx = -1, rx = 1e18 + 1;
		while (l <= r) {
			ll mn, mx;
			MinMax(lx, rx, &mn, &mx);
			// cout << '\t' << lx << ' ' << rx << ' ' << mn << ' ' << mx << endl;
			a[l++] = mn, a[r--] = mx;
			lx = mn + 1, rx = mx - 1;
		}
		ll ans = 0;
		for (int i = 1; i < n; i++) ans = max(ans, a[i] - a[i - 1]);

		return ans;
	}

	ll start, end;
	MinMax(0, 1e18, &start, &end);
	ll avg = (end - start) / (n - 1);
	ll last = start, r = min(end - 1, start + avg), ans = avg;
	// cout << '\t' << start << ' ' << end << ' ' << avg << endl;
	while (true) {
		ll mn, mx;
		if (last + 1 > r or r >= end) break;
		MinMax(last + 1, r, &mn, &mx);
		// cout << '\t' << last << ' ' << r << ' ' << mn << ' ' << mx << endl;
		if (mn == -1) {
			r += ans;
			continue;
		}
		if (mn == mx) ans = max(ans, mx - last);
		last = mx, r = mx + ans;
	}
	ans = max(ans, end - last);

	return ans;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...