제출 #47656

#제출 시각아이디문제언어결과실행 시간메모리
47656E869120Gap (APIO16_gap)C++14
50.36 / 100
151 ms2308 KiB
#include "gap.h"
#include <algorithm>
#include <iostream>
using namespace std;

long long a[100009]; int res = 0;

void saiki(long long L, long long R) {
	if (L >= R) return;
	long long s, t;
	MinMax(L, R - 1, &s, &t);
	if (s == -1) return;
	if (s == t) { res++; a[res] = s; return; }

	t++;
	long long B[31];
	if (t - s >= (1LL << 60)) { for (int i = 0; i <= 8; i++) { long double V = 1.0L*i / 8.0L; B[i] = (1.0L*s*(1.0L - V) + 1.0L*t*V); } }
	else { for (int i = 0; i <= 8; i++) B[i] = (s*(8LL - i) + t*i) / 8LL; }
	for (int i = 0; i < 8; i++) saiki(B[i], B[i + 1]);
}

long long findGap(int T, int N)
{
	if (T == 1) {
		long long L = 0, R = 1000000000000000000LL, s, t, cnt = 0;

		while (cnt < (N + 1) / 2) {
			MinMax(L, R, &s, &t);
			L = s; R = t;
			if (L != -1) { a[cnt + 1] = L; a[N - cnt] = R; }
			cnt++; L++; R--;
		}
		long long maxn = 0;
		for (int i = 1; i <= N - 1; i++) maxn = max(maxn, a[i + 1] - a[i]);
		return maxn;
	}
	if (T == 2) {
		saiki(0LL, 1000000000000000001LL);
		long long maxn = 0;
		for (int i = 1; i <= N - 1; i++) maxn = max(maxn, a[i + 1] - a[i]);
		return maxn;
	}
	return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...