Submission #1091862

# Submission time Handle Problem Language Result Execution time Memory
1091862 2024-09-22T11:21:44 Z lovrot Gap (APIO16_gap) C++17
100 / 100
45 ms 9012 KB
#include "gap.h"
#include <cstdio>
#include <algorithm>

#define X first
#define Y second
#define PB push_back
#define debug(...) fprintf(stderr, __VA_ARGS__)

using namespace std; 

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const ll OO = 1e18;
const int N = 5e5 + 10;

int cnt = 0;

pll query(ll a, ll b) { 
	if(a > b) { return {-1, -1}; }
	ll ret, ret_;
	++cnt;
	MinMax(a, b, &ret, &ret_);
	return {ret, ret_};
}

ll solve(ll lst, ll l, ll r, int n) { 
	if(n == 1) { return 0; }
	pll res = query(l, l + (r - l) / (n - 1)); 
	return max(res.X - lst, solve(max(lst, res.Y), l + (r - l) / (n - 1) + 1, r, n - 1));
}

ll niz[N];

ll findGap(int T, int n) {
	if(T == 1) { 
		int minp = 0;
		int maxp = n - 1;
		ll mn = 0, minr;
		ll mx = OO, maxr;
	 
		while(minp <= maxp){ 
			MinMax(mn, mx, &minr, &maxr);
			niz[minp] = minr;
			niz[maxp] = maxr;
			mn = minr + 1;
			mx = maxr - 1; 
			minp++;
			maxp--;
		}
	 
		ll ans = 0;
		for(int i = 0; i < n - 1; i++) ans = max(ans, niz[i + 1] - niz[i]);
		return ans; cnt = 0;
	}
	pll res = query(0, OO);
	ll ret = solve(res.X, res.X + 1, res.Y, n);
	return ret;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 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 388 KB Output is correct
6 Correct 0 ms 344 KB Output is correct
7 Correct 0 ms 344 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
9 Correct 1 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 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 7 ms 580 KB Output is correct
17 Correct 7 ms 600 KB Output is correct
18 Correct 9 ms 672 KB Output is correct
19 Correct 6 ms 600 KB Output is correct
20 Correct 7 ms 600 KB Output is correct
21 Correct 25 ms 1872 KB Output is correct
22 Correct 25 ms 1880 KB Output is correct
23 Correct 29 ms 1876 KB Output is correct
24 Correct 30 ms 1872 KB Output is correct
25 Correct 26 ms 1876 KB Output is correct
26 Correct 39 ms 1872 KB Output is correct
27 Correct 26 ms 1880 KB Output is correct
28 Correct 31 ms 1880 KB Output is correct
29 Correct 31 ms 1872 KB Output is correct
30 Correct 21 ms 1952 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 0 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 392 KB Output is correct
6 Correct 0 ms 344 KB Output is correct
7 Correct 0 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 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 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 11 ms 2392 KB Output is correct
17 Correct 9 ms 2392 KB Output is correct
18 Correct 9 ms 2392 KB Output is correct
19 Correct 10 ms 2392 KB Output is correct
20 Correct 6 ms 2392 KB Output is correct
21 Correct 42 ms 8860 KB Output is correct
22 Correct 38 ms 8784 KB Output is correct
23 Correct 41 ms 9012 KB Output is correct
24 Correct 43 ms 8892 KB Output is correct
25 Correct 38 ms 8784 KB Output is correct
26 Correct 45 ms 8784 KB Output is correct
27 Correct 43 ms 8784 KB Output is correct
28 Correct 42 ms 8784 KB Output is correct
29 Correct 41 ms 8932 KB Output is correct
30 Correct 33 ms 8784 KB Output is correct
31 Correct 0 ms 344 KB Output is correct
32 Correct 0 ms 344 KB Output is correct