Submission #385761

# Submission time Handle Problem Language Result Execution time Memory
385761 2021-04-04T22:41:13 Z idontreallyknow Gap (APIO16_gap) C++17
100 / 100
71 ms 5884 KB
#include <bits/stdc++.h>
#include "gap.h"
using namespace std;
typedef long long ll;
long long findGap(int t, int n)
{
	ll lo = 0, hi = (ll)1e18;
	if (t == 1) {
		ll le = 0, ri = n-1, x, y;
		vector<ll> a(n);
		while (le <= ri) {
			MinMax(lo,hi,&x,&y);
			if (x == -1) break;
			a[le] = x;
			a[ri] = y;
			lo = x+1;
			hi = y-1;
			le++;
			ri--;
		}
		ll ans = 0;
		for (int q = 1; q < n; q++) {
			ans = max(ans, a[q]-a[q-1]);
		}
		return ans;
	} else {
		ll x,y;
		MinMax(lo,hi,&x,&y);
		if (n == 2) return y-x;
		ll piece = (y-x-1)/(n-1);
		ll add = y-x-1-(n-1)*piece;
		vector<pair<ll,ll>> inter;
		ll last = x;
		for (int q = 0; q < n-1; q++) {
			inter.emplace_back(last+1,last+1+piece);
			if (add > 0) inter.back().second++;
			last = inter.back().second;
		}
		ll a,b;
		vector<pair<ll,ll>> res;
		for (int q = 0; q < n-1; q++) {
			MinMax(inter[q].first,inter[q].second,&a,&b);
			res.emplace_back(a,b);
		}
		ll ans = 0;
		last = x;
		for (int q = 0; q < n-1; q++) {
			if (res[q].first == -1) continue;
			ans = max(ans, res[q].first-last);
			last = res[q].second;
		}
		ans = max(ans, y-last);
		return ans;
	}
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 2 ms 364 KB Output is correct
13 Correct 2 ms 364 KB Output is correct
14 Correct 2 ms 364 KB Output is correct
15 Correct 2 ms 364 KB Output is correct
16 Correct 14 ms 824 KB Output is correct
17 Correct 12 ms 896 KB Output is correct
18 Correct 12 ms 748 KB Output is correct
19 Correct 12 ms 748 KB Output is correct
20 Correct 9 ms 748 KB Output is correct
21 Correct 48 ms 1876 KB Output is correct
22 Correct 55 ms 1900 KB Output is correct
23 Correct 44 ms 2028 KB Output is correct
24 Correct 44 ms 1900 KB Output is correct
25 Correct 39 ms 1900 KB Output is correct
26 Correct 51 ms 1900 KB Output is correct
27 Correct 54 ms 1960 KB Output is correct
28 Correct 44 ms 1900 KB Output is correct
29 Correct 45 ms 2156 KB Output is correct
30 Correct 35 ms 1900 KB Output is correct
31 Correct 1 ms 364 KB Output is correct
32 Correct 1 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 2 ms 492 KB Output is correct
12 Correct 2 ms 492 KB Output is correct
13 Correct 2 ms 492 KB Output is correct
14 Correct 2 ms 492 KB Output is correct
15 Correct 3 ms 492 KB Output is correct
16 Correct 16 ms 1636 KB Output is correct
17 Correct 17 ms 1636 KB Output is correct
18 Correct 16 ms 1636 KB Output is correct
19 Correct 18 ms 1636 KB Output is correct
20 Correct 9 ms 1636 KB Output is correct
21 Correct 65 ms 5724 KB Output is correct
22 Correct 66 ms 5724 KB Output is correct
23 Correct 71 ms 5724 KB Output is correct
24 Correct 65 ms 5804 KB Output is correct
25 Correct 61 ms 5724 KB Output is correct
26 Correct 68 ms 5796 KB Output is correct
27 Correct 65 ms 5884 KB Output is correct
28 Correct 66 ms 5852 KB Output is correct
29 Correct 66 ms 5724 KB Output is correct
30 Correct 38 ms 5724 KB Output is correct
31 Correct 1 ms 364 KB Output is correct
32 Correct 1 ms 364 KB Output is correct