Submission #1076893

# Submission time Handle Problem Language Result Execution time Memory
1076893 2024-08-26T18:06:41 Z TFF Gap (APIO16_gap) C++17
100 / 100
45 ms 3168 KB
#include <bits/stdc++.h>
#include "gap.h"
using namespace std;
const long long MX = 1000000000000000000;
long long mn, mx;
int n;
long long findGap(int t, int N) {
	n = N;
    if (t == 1) {
		long long left, right;
		left = 0;
		right = MX;
		vector<long long> arr1, arr2;
		for (int i = 0; i < (n + 1) / 2; i++) {
			MinMax(left, right, &mn, &mx);
			arr1.push_back(mn);
			arr2.push_back(mx);
			left = mn + 1;
			right = mx - 1;
		}
		long long ans = arr2.back() - arr1.back();
		for (int i = 0; i < (int)arr1.size() - 1; i++) {
			ans = max(ans, arr1[i + 1] - arr1[i]);
			ans = max(ans, arr2[i] - arr2[i + 1]);
		}
		return ans;
	}
	MinMax(0, MX, &mn, &mx);
	long long left = mn;
	long long right = mx;
	long long delta = (mx - mn + n - 2) / (n - 1);
	vector<long long> pos;
	pos.push_back(left);
	for (int i = 0; i < n - 1; i++) {
		MinMax(min(left + i * delta + 1, right), min(left + (i + 1) * delta, right), &mn, &mx);
		if (mn != -1) {
			pos.push_back(mn);
			pos.push_back(mx);
		}
		if (left + (i + 1) * delta >= right) break;
	}
	pos.push_back(right);
	long long ans = 0;
	for (int i = 0; i < (int)pos.size(); i++) {
		ans = max(ans, pos[i + 1] - pos[i]);
	}
	return ans;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 596 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 0 ms 344 KB Output is correct
7 Correct 0 ms 344 KB Output is correct
8 Correct 1 ms 344 KB Output is correct
9 Correct 0 ms 344 KB Output is correct
10 Correct 0 ms 344 KB Output is correct
11 Correct 1 ms 344 KB Output is correct
12 Correct 1 ms 344 KB Output is correct
13 Correct 0 ms 344 KB Output is correct
14 Correct 1 ms 344 KB Output is correct
15 Correct 1 ms 344 KB Output is correct
16 Correct 6 ms 936 KB Output is correct
17 Correct 10 ms 856 KB Output is correct
18 Correct 6 ms 856 KB Output is correct
19 Correct 8 ms 856 KB Output is correct
20 Correct 6 ms 856 KB Output is correct
21 Correct 31 ms 2008 KB Output is correct
22 Correct 26 ms 1924 KB Output is correct
23 Correct 35 ms 1916 KB Output is correct
24 Correct 26 ms 1920 KB Output is correct
25 Correct 25 ms 1924 KB Output is correct
26 Correct 29 ms 1916 KB Output is correct
27 Correct 27 ms 2172 KB Output is correct
28 Correct 31 ms 1924 KB Output is correct
29 Correct 35 ms 1920 KB Output is correct
30 Correct 21 ms 1924 KB Output is correct
31 Correct 0 ms 344 KB Output is correct
32 Correct 0 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 1 ms 344 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 0 ms 344 KB Output is correct
7 Correct 1 ms 344 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
9 Correct 0 ms 344 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
11 Correct 1 ms 344 KB Output is correct
12 Correct 1 ms 344 KB Output is correct
13 Correct 1 ms 344 KB Output is correct
14 Correct 1 ms 344 KB Output is correct
15 Correct 1 ms 344 KB Output is correct
16 Correct 9 ms 980 KB Output is correct
17 Correct 9 ms 972 KB Output is correct
18 Correct 11 ms 980 KB Output is correct
19 Correct 9 ms 900 KB Output is correct
20 Correct 5 ms 500 KB Output is correct
21 Correct 41 ms 2256 KB Output is correct
22 Correct 35 ms 2228 KB Output is correct
23 Correct 45 ms 2248 KB Output is correct
24 Correct 36 ms 2256 KB Output is correct
25 Correct 44 ms 3168 KB Output is correct
26 Correct 36 ms 2316 KB Output is correct
27 Correct 37 ms 2256 KB Output is correct
28 Correct 37 ms 2212 KB Output is correct
29 Correct 36 ms 2196 KB Output is correct
30 Correct 21 ms 1484 KB Output is correct
31 Correct 0 ms 344 KB Output is correct
32 Correct 1 ms 344 KB Output is correct