제출 #262025

#제출 시각아이디문제언어결과실행 시간메모리
262025amoo_safarGap (APIO16_gap)C++17
100 / 100
78 ms3308 KiB
#include <bits/stdc++.h>
#include "gap.h"

#define pb push_back

using namespace std;

typedef long long ll;

const ll Inf = 1e18;

ll findGap(int Tc, int N){
	if(Tc == 1){
		vector<ll> V;

		ll L, R, L2, R2;
		MinMax(0ll, Inf, &L, &R);
		V.pb(L);
		V.pb(R);
		while( ((int) V.size()) < N){
			L ++;
			R --;
			MinMax(L, R, &L2, &R2);
			L = L2;
			R = R2;
			V.pb(L); V.pb(R);
		}
		sort(V.begin(), V.end());
		
		ll ans = 0;
		for(int i = 0; i + 1 < (int) V.size(); i++) ans = max(ans, V[i + 1] - V[i]);
		return ans;	
	}
	ll L, R, S, T;
	MinMax(0ll, Inf, &L, &R);
	ll D = (R - L) / (N - 1);
	ll md = (R - L) % (N - 1);
	ll pos = L;
	ll st;
	vector<ll> V;
	V.pb(L);
	V.pb(R);
	for(int i = 0; i < N - 1; i++){
		st = D;
		if(i < md) st ++;
		MinMax(pos, pos + st - 1, &S, &T);
		if(S != -1){
			V.push_back(S);
			V.push_back(T);
		}
		pos += st;
	}
	sort(V.begin(), V.end());
	ll ans = D + min(md, 1ll);
	for(int i = 0; i + 1 < (int) V.size(); i++) ans = max(ans, V[i + 1] - V[i]);
	return ans;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...