Submission #125823

#TimeUsernameProblemLanguageResultExecution timeMemory
125823dragoonGap (APIO16_gap)C++14
100 / 100
83 ms5252 KiB
#include "gap.h"
#include <vector>
#include <algorithm>
using namespace std;

typedef long long LL;

LL Solve1(int N) {
	vector<LL> V(N, 0);
	LL a = 0, b = 1000000000000000000LL;
	a--, b++;
	for (int i = 0, j = N - 1; i <= j; i++, j--) {
		LL c, d;
		MinMax(a, b, &c, &d);
		V[i] = c;
		V[j] = d;
		a = c + 1;
		b = d - 1;
	}
	LL ans = 0;
	for (int i = 0; i < N - 1; i++) ans = max(ans, V[i + 1] - V[i]);
	return ans;
}

LL Solve2(int N) {
	vector<LL> V;
	LL a = 0, b = 1000000000000000000LL;
	a--, b++;
	{
		LL c, d;
		MinMax(a, b, &c, &d);
		a = c, b = d;
	}
	if (N <= 2) return b - a;
	LL gap = (b - a + N - 2)/(N - 1);
	V.push_back(a);
	V.push_back(b);
	for (LL i = a; i <= b; i += gap + 1) {
		LL c, d;
		MinMax(i, i + gap, &c, &d);
		V.push_back(c);
		V.push_back(d);
	}
	sort(V.begin(), V.end());
	LL ans = 0;
	for (int i = 1; i < V.size(); i++) ans = max(ans, V[i] - V[i - 1]);
	return ans;
}

long long findGap(int T, int N)
{
	if (T == 1) return Solve1(N);
	else return Solve2(N);
}

Compilation message (stderr)

gap.cpp: In function 'LL Solve2(int)':
gap.cpp:46:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for (int i = 1; i < V.size(); i++) ans = max(ans, V[i] - V[i - 1]);
                  ~~^~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...