Submission #844821

# Submission time Handle Problem Language Result Execution time Memory
844821 2023-09-06T01:58:02 Z dutinmeow Gap (APIO16_gap) C++17
83.5083 / 100
41 ms 3868 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);
		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 0 ms 2392 KB Output is correct
4 Correct 0 ms 2392 KB Output is correct
5 Correct 1 ms 2392 KB Output is correct
6 Correct 1 ms 2392 KB Output is correct
7 Correct 1 ms 2392 KB Output is correct
8 Correct 0 ms 2392 KB Output is correct
9 Correct 1 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 2584 KB Output is correct
17 Correct 11 ms 2588 KB Output is correct
18 Correct 9 ms 2560 KB Output is correct
19 Correct 8 ms 2580 KB Output is correct
20 Correct 7 ms 2572 KB Output is correct
21 Correct 34 ms 3576 KB Output is correct
22 Correct 32 ms 3496 KB Output is correct
23 Correct 31 ms 3616 KB Output is correct
24 Correct 37 ms 3536 KB Output is correct
25 Correct 27 ms 3612 KB Output is correct
26 Correct 32 ms 3408 KB Output is correct
27 Correct 31 ms 3868 KB Output is correct
28 Correct 31 ms 3480 KB Output is correct
29 Correct 30 ms 3628 KB Output is correct
30 Correct 26 ms 3616 KB Output is correct
31 Correct 0 ms 2392 KB Output is correct
32 Correct 1 ms 2392 KB Output is correct
# Verdict Execution time Memory Grader output
1 Partially correct 1 ms 2392 KB Partially 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 Partially correct 1 ms 2392 KB Partially correct
6 Correct 0 ms 2392 KB Output is correct
7 Correct 0 ms 2392 KB Output is correct
8 Correct 1 ms 2392 KB Output is correct
9 Correct 1 ms 2544 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 Partially correct 1 ms 2392 KB Partially correct
16 Correct 12 ms 2596 KB Output is correct
17 Correct 9 ms 2584 KB Output is correct
18 Correct 10 ms 2592 KB Output is correct
19 Correct 11 ms 2832 KB Output is correct
20 Correct 5 ms 2580 KB Output is correct
21 Correct 38 ms 2856 KB Output is correct
22 Correct 38 ms 3100 KB Output is correct
23 Correct 38 ms 2860 KB Output is correct
24 Correct 38 ms 2860 KB Output is correct
25 Partially correct 36 ms 2852 KB Partially correct
26 Correct 38 ms 2852 KB Output is correct
27 Correct 41 ms 2852 KB Output is correct
28 Correct 38 ms 2856 KB Output is correct
29 Correct 38 ms 2856 KB Output is correct
30 Correct 21 ms 2852 KB Output is correct
31 Partially correct 1 ms 2392 KB Partially correct
32 Partially correct 1 ms 2392 KB Partially correct