Submission #844824

# Submission time Handle Problem Language Result Execution time Memory
844824 2023-09-06T02:03:03 Z dutinmeow Gap (APIO16_gap) C++17
100 / 100
41 ms 3848 KB
#include "gap.h"

#include <bits/stdc++.h>

template<typename T>
bool chmax(T &a, T b) { 
	if (a >= b)
		return false;
	a = b;
	return true;
}

long long findGap(int t, int n) {
	if (t == 1) {
		std::vector<long long> a;
		a.reserve(n);
		long long bl = 0, br = 1e18;
		for (int i = 0; i < (n + 1) / 2; i++) {
			long long al, ar;
			MinMax(bl, br, &al, &ar);
			a.push_back(al);
			a.push_back(ar);
			bl = al + 1, br = ar - 1;
		}
		if ((int)a.size() > n)
			a.pop_back();
		std::sort(a.begin(), a.end());
		long long r = 0;
		for (int i = 1; i < n; i++)
			chmax(r, a[i] - a[i - 1]);
		return r;
	} else {
		long long bl, br;
		MinMax(1, 1e18, &bl, &br);
		long long s = (br - bl - 1) / (n - 1) + 1;
		long long lb, c = bl, r = s;
		for (lb = bl; lb + s < br; lb += s + 1) {
			long long nl, nr;
			MinMax(lb, lb + s, &nl, &nr);
			if (nl != -1 && nr != -1) {
				chmax(r, nl - c);
				c = nr;
			}
		} 
		long long nl, nr;
		MinMax(lb, br, &nl, &nr);
		if (nl != -1 && nr != -1) 
			chmax(r, nl - c);
		return r;
	}
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 2392 KB Output is correct
3 Correct 1 ms 2392 KB Output is correct
4 Correct 0 ms 2392 KB Output is correct
5 Correct 1 ms 2668 KB Output is correct
6 Correct 1 ms 2392 KB Output is correct
7 Correct 0 ms 2392 KB Output is correct
8 Correct 0 ms 2392 KB Output is correct
9 Correct 0 ms 2392 KB Output is correct
10 Correct 0 ms 2392 KB Output is correct
11 Correct 1 ms 2392 KB Output is correct
12 Correct 1 ms 2392 KB Output is correct
13 Correct 1 ms 2392 KB Output is correct
14 Correct 1 ms 2392 KB Output is correct
15 Correct 1 ms 2392 KB Output is correct
16 Correct 8 ms 2588 KB Output is correct
17 Correct 8 ms 2580 KB Output is correct
18 Correct 8 ms 2744 KB Output is correct
19 Correct 8 ms 2580 KB Output is correct
20 Correct 6 ms 2612 KB Output is correct
21 Correct 30 ms 3616 KB Output is correct
22 Correct 36 ms 3408 KB Output is correct
23 Correct 31 ms 3456 KB Output is correct
24 Correct 31 ms 3620 KB Output is correct
25 Correct 28 ms 3608 KB Output is correct
26 Correct 31 ms 3604 KB Output is correct
27 Correct 31 ms 3848 KB Output is correct
28 Correct 33 ms 3448 KB Output is correct
29 Correct 35 ms 3408 KB Output is correct
30 Correct 27 ms 3552 KB Output is correct
31 Correct 1 ms 2392 KB Output is correct
32 Correct 1 ms 2392 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 2392 KB Output is correct
2 Correct 0 ms 2392 KB Output is correct
3 Correct 1 ms 2392 KB Output is correct
4 Correct 1 ms 2392 KB Output is correct
5 Correct 1 ms 2644 KB Output is correct
6 Correct 1 ms 2552 KB Output is correct
7 Correct 1 ms 2392 KB Output is correct
8 Correct 0 ms 2392 KB Output is correct
9 Correct 0 ms 2392 KB Output is correct
10 Correct 0 ms 2392 KB Output is correct
11 Correct 1 ms 2392 KB Output is correct
12 Correct 1 ms 2392 KB Output is correct
13 Correct 1 ms 2392 KB Output is correct
14 Correct 1 ms 2392 KB Output is correct
15 Correct 1 ms 2392 KB Output is correct
16 Correct 9 ms 2724 KB Output is correct
17 Correct 10 ms 2752 KB Output is correct
18 Correct 11 ms 2588 KB Output is correct
19 Correct 10 ms 2588 KB Output is correct
20 Correct 5 ms 2572 KB Output is correct
21 Correct 38 ms 2860 KB Output is correct
22 Correct 38 ms 2856 KB Output is correct
23 Correct 38 ms 2860 KB Output is correct
24 Correct 41 ms 2864 KB Output is correct
25 Correct 36 ms 2856 KB Output is correct
26 Correct 40 ms 2860 KB Output is correct
27 Correct 40 ms 2852 KB Output is correct
28 Correct 38 ms 2860 KB Output is correct
29 Correct 39 ms 2864 KB Output is correct
30 Correct 20 ms 2852 KB Output is correct
31 Correct 0 ms 2392 KB Output is correct
32 Correct 0 ms 2392 KB Output is correct