Submission #101832

# Submission time Handle Problem Language Result Execution time Memory
101832 2019-03-20T12:30:45 Z cerberus Gap (APIO16_gap) C++17
0 / 100
78 ms 3068 KB
/* cerberus97 - Hanit Banga */

#include <iostream>
#include <iomanip>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>

#include "gap.h"

using namespace std;

#define pb push_back
#define fast_cin() ios_base::sync_with_stdio(false); cin.tie(NULL)

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

const ll INF = 1e18;

ll findGap(int T, int N);
void query(ll s, ll t, ll &mn, ll &mx);

int M;
set<pll> S;

#ifdef LOCAL
int main() {
	int n; cin >> n;
	vector<ll> v(n);
	for (int i = 1; i <= n; ++i) {
		cin >> v[i - 1];
	}
	sort(v.begin(), v.end());
	for (int i = 0; i < n; ++i) {
		S.insert({v[i], i});
	}
	S.insert({-1, -1});
	S.insert({INF + 1, n});
	cout << findGap(1, n) << endl << M << ' ' << 3 * n << endl;
}
#endif

ll findGap(int T, int N) {
	ll mn, mx;
	query(0, INF, mn, mx);
	if (N <= 2) {
		return mx - mn;
	}

	ll A = mn, B = mx, best = (B - A + N - 2) / (N - 1), sz = best + 1;
	while (A < B) {
		if (A + sz >= B) {
			query(A + 1, B - 1, mn, mx);
			mx = B;
			if (mn == -1) {
				mn = B;
			}
		} else {
			query(A + 1, A + sz, mn, mx);
		}
		if (mn == -1) {
			sz *= 2;
			continue;
		}
		best = max(best, mn - A);
		A = mx;
	}
	return best;
}

void query(ll s, ll t, ll &mn, ll &mx) {
	if (s > t) {
		mn = mx = -1;
		return;
	}
#ifdef LOCAL
	assert(s <= t);
	++M;
	auto l = S.lower_bound({s, -INF});
	auto r = S.upper_bound({t, INF + 10});
	--r;
	if (l->second <= r->second) {
		mn = l->first;
		mx = r->first;
		M += (r->second - l->second + 1);
	} else {
		mn = mx = -1;
	}
#else
	MinMax(s, t, &mn, &mx);
#endif
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 384 KB Output is correct
2 Incorrect 2 ms 384 KB Output isn't correct
3 Incorrect 2 ms 384 KB Output isn't correct
4 Incorrect 2 ms 384 KB Output isn't correct
5 Incorrect 3 ms 384 KB Output isn't correct
6 Correct 2 ms 384 KB Output is correct
7 Correct 2 ms 384 KB Output is correct
8 Correct 2 ms 256 KB Output is correct
9 Correct 3 ms 384 KB Output is correct
10 Correct 2 ms 384 KB Output is correct
11 Correct 2 ms 384 KB Output is correct
12 Correct 2 ms 384 KB Output is correct
13 Correct 2 ms 384 KB Output is correct
14 Correct 2 ms 384 KB Output is correct
15 Incorrect 3 ms 384 KB Output isn't correct
16 Correct 10 ms 1024 KB Output is correct
17 Correct 11 ms 1024 KB Output is correct
18 Correct 13 ms 1024 KB Output is correct
19 Correct 14 ms 1024 KB Output is correct
20 Correct 7 ms 640 KB Output is correct
21 Correct 58 ms 2936 KB Output is correct
22 Correct 37 ms 2936 KB Output is correct
23 Correct 30 ms 3068 KB Output is correct
24 Correct 48 ms 2980 KB Output is correct
25 Incorrect 62 ms 2304 KB Output isn't correct
26 Correct 52 ms 2936 KB Output is correct
27 Correct 78 ms 3064 KB Output is correct
28 Correct 33 ms 2944 KB Output is correct
29 Correct 32 ms 2936 KB Output is correct
30 Correct 18 ms 1792 KB Output is correct
31 Correct 4 ms 384 KB Output is correct
32 Correct 2 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 256 KB Output is correct
2 Incorrect 2 ms 384 KB Output isn't correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 2 ms 384 KB Output is correct
5 Correct 2 ms 384 KB Output is correct
6 Correct 2 ms 384 KB Output is correct
7 Correct 2 ms 384 KB Output is correct
8 Correct 2 ms 384 KB Output is correct
9 Correct 2 ms 384 KB Output is correct
10 Correct 3 ms 384 KB Output is correct
11 Correct 3 ms 304 KB Output is correct
12 Correct 3 ms 384 KB Output is correct
13 Correct 3 ms 384 KB Output is correct
14 Correct 4 ms 384 KB Output is correct
15 Correct 3 ms 384 KB Output is correct
16 Correct 12 ms 1024 KB Output is correct
17 Incorrect 11 ms 1024 KB Output isn't correct
18 Correct 14 ms 896 KB Output is correct
19 Correct 15 ms 1024 KB Output is correct
20 Correct 7 ms 640 KB Output is correct
21 Correct 38 ms 2936 KB Output is correct
22 Correct 37 ms 2936 KB Output is correct
23 Correct 48 ms 2908 KB Output is correct
24 Correct 46 ms 3064 KB Output is correct
25 Correct 64 ms 2348 KB Output is correct
26 Correct 34 ms 2896 KB Output is correct
27 Incorrect 51 ms 2936 KB Output isn't correct
28 Incorrect 49 ms 2936 KB Output isn't correct
29 Correct 35 ms 2936 KB Output is correct
30 Correct 17 ms 1792 KB Output is correct
31 Correct 2 ms 384 KB Output is correct
32 Correct 2 ms 384 KB Output is correct