Submission #125823

# Submission time Handle Problem Language Result Execution time Memory
125823 2019-07-06T12:11:05 Z dragoon Gap (APIO16_gap) C++14
100 / 100
83 ms 5252 KB
#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

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 time Memory Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 2 ms 256 KB Output is correct
3 Correct 2 ms 256 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 256 KB Output is correct
6 Correct 2 ms 256 KB Output is correct
7 Correct 2 ms 252 KB Output is correct
8 Correct 2 ms 256 KB Output is correct
9 Correct 2 ms 256 KB Output is correct
10 Correct 2 ms 348 KB Output is correct
11 Correct 3 ms 376 KB Output is correct
12 Correct 3 ms 376 KB Output is correct
13 Correct 3 ms 380 KB Output is correct
14 Correct 3 ms 376 KB Output is correct
15 Correct 3 ms 376 KB Output is correct
16 Correct 15 ms 1144 KB Output is correct
17 Correct 15 ms 1208 KB Output is correct
18 Correct 15 ms 1144 KB Output is correct
19 Correct 15 ms 1144 KB Output is correct
20 Correct 11 ms 892 KB Output is correct
21 Correct 54 ms 3704 KB Output is correct
22 Correct 54 ms 3704 KB Output is correct
23 Correct 54 ms 3704 KB Output is correct
24 Correct 54 ms 3704 KB Output is correct
25 Correct 47 ms 3156 KB Output is correct
26 Correct 54 ms 3704 KB Output is correct
27 Correct 54 ms 3704 KB Output is correct
28 Correct 54 ms 3704 KB Output is correct
29 Correct 53 ms 3704 KB Output is correct
30 Correct 39 ms 2556 KB Output is correct
31 Correct 2 ms 256 KB Output is correct
32 Correct 2 ms 256 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 256 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 256 KB Output is correct
6 Correct 2 ms 256 KB Output is correct
7 Correct 2 ms 256 KB Output is correct
8 Correct 2 ms 256 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 3 ms 376 KB Output is correct
12 Correct 3 ms 348 KB Output is correct
13 Correct 3 ms 376 KB Output is correct
14 Correct 3 ms 376 KB Output is correct
15 Correct 3 ms 424 KB Output is correct
16 Correct 21 ms 1652 KB Output is correct
17 Correct 21 ms 1652 KB Output is correct
18 Correct 21 ms 1672 KB Output is correct
19 Correct 21 ms 1752 KB Output is correct
20 Correct 11 ms 1268 KB Output is correct
21 Correct 83 ms 5144 KB Output is correct
22 Correct 82 ms 5096 KB Output is correct
23 Correct 82 ms 5252 KB Output is correct
24 Correct 82 ms 5100 KB Output is correct
25 Correct 73 ms 4556 KB Output is correct
26 Correct 82 ms 5096 KB Output is correct
27 Correct 81 ms 5096 KB Output is correct
28 Correct 81 ms 5072 KB Output is correct
29 Correct 83 ms 5228 KB Output is correct
30 Correct 42 ms 3956 KB Output is correct
31 Correct 2 ms 256 KB Output is correct
32 Correct 2 ms 376 KB Output is correct