Submission #23463

# Submission time Handle Problem Language Result Execution time Memory
23463 2017-05-09T17:34:07 Z ztrong Gap (APIO16_gap) C++14
100 / 100
66 ms 6516 KB
#include <bits/stdc++.h>
#include "gap.h"

using namespace std;

#define FOR(i, a, b) for (int i = a, _b = b; i <= _b; ++i)
#define FORD(i, a, b) for (int i = a, _b = b; i >= _b; --i)
#define REP(i, a) for (int i = 0, _a = a; i < _a; ++i)
#define llint long long
#define sz(x) (x.size())
#define LL(x) (x * 2)
#define RR(x) (x * 2 + 1)
#define fi first
#define se second
#define db(x) cout << #x << " = " << x << endl;
#define BIT(x, i) ((x >> i) & 1)
#define MASK(i) (1ll << i)
#define times clock() * 1.0 / CLOCKS_PER_SEC

void openFile() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
}

const int maxN = 1e5 + 5;
const int maxM = 1e6 + 5;
const llint INF = 1e18 + 100;

vector<llint> lef, rig;
llint findGap(int T, int N) {
	if (T == 1) {
		llint l = -1, r = INF;
		llint nl = 0, nr = 0;
		llint res = 0;
		FOR(i, 1, (N + 1) / 2) {
			MinMax(l + 1, r - 1, &nl, &nr);
			lef.push_back(nl);
			rig.push_back(nr);
			l = nl; r = nr;
		}
		FOR(i, 1, lef.size() - 1) {
			res = max(res, lef[i] - lef[i - 1]);
		}
		FOR(i, 1, rig.size() - 1) {
			res = max(res, rig[i - 1] - rig[i]);
		}
		res = max(res, rig.back() - lef.back());
		return res;
	}
	else {
		llint l, r;
		MinMax(-1, INF, &l, &r);
		if (N == 2) {
			return r - l;
		}
		llint lower = (r - l) / (N - 1);
		llint nl, nr;
		do {
			llint x = 0;
			nl = nr = -1;
			while (nl == -1) {
				++x;
				MinMax(l + 1, l + lower * x, &nl, &nr);
			}

			lower = max(lower, nl - l);
			l = nr;
		} while (l != r);
		return lower;
	}
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 5144 KB Output is correct
2 Correct 0 ms 5144 KB Output is correct
3 Correct 0 ms 5144 KB Output is correct
4 Correct 0 ms 5144 KB Output is correct
5 Correct 0 ms 5144 KB Output is correct
6 Correct 0 ms 5144 KB Output is correct
7 Correct 0 ms 5144 KB Output is correct
8 Correct 0 ms 5144 KB Output is correct
9 Correct 0 ms 5144 KB Output is correct
10 Correct 0 ms 5144 KB Output is correct
11 Correct 0 ms 5144 KB Output is correct
12 Correct 0 ms 5144 KB Output is correct
13 Correct 0 ms 5144 KB Output is correct
14 Correct 0 ms 5144 KB Output is correct
15 Correct 0 ms 5144 KB Output is correct
16 Correct 9 ms 5436 KB Output is correct
17 Correct 13 ms 5436 KB Output is correct
18 Correct 13 ms 5436 KB Output is correct
19 Correct 13 ms 5436 KB Output is correct
20 Correct 6 ms 5436 KB Output is correct
21 Correct 53 ms 6516 KB Output is correct
22 Correct 56 ms 6516 KB Output is correct
23 Correct 53 ms 6516 KB Output is correct
24 Correct 49 ms 6516 KB Output is correct
25 Correct 39 ms 6516 KB Output is correct
26 Correct 46 ms 6516 KB Output is correct
27 Correct 49 ms 6516 KB Output is correct
28 Correct 59 ms 6516 KB Output is correct
29 Correct 56 ms 6516 KB Output is correct
30 Correct 43 ms 6516 KB Output is correct
31 Correct 0 ms 5144 KB Output is correct
32 Correct 0 ms 5144 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 5144 KB Output is correct
2 Correct 0 ms 5144 KB Output is correct
3 Correct 0 ms 5144 KB Output is correct
4 Correct 0 ms 5144 KB Output is correct
5 Correct 0 ms 5144 KB Output is correct
6 Correct 0 ms 5144 KB Output is correct
7 Correct 0 ms 5144 KB Output is correct
8 Correct 0 ms 5144 KB Output is correct
9 Correct 0 ms 5144 KB Output is correct
10 Correct 0 ms 5144 KB Output is correct
11 Correct 0 ms 5144 KB Output is correct
12 Correct 0 ms 5144 KB Output is correct
13 Correct 0 ms 5144 KB Output is correct
14 Correct 0 ms 5144 KB Output is correct
15 Correct 0 ms 5144 KB Output is correct
16 Correct 9 ms 5144 KB Output is correct
17 Correct 9 ms 5144 KB Output is correct
18 Correct 9 ms 5144 KB Output is correct
19 Correct 16 ms 5144 KB Output is correct
20 Correct 6 ms 5144 KB Output is correct
21 Correct 29 ms 5144 KB Output is correct
22 Correct 43 ms 5144 KB Output is correct
23 Correct 39 ms 5144 KB Output is correct
24 Correct 29 ms 5144 KB Output is correct
25 Correct 66 ms 5144 KB Output is correct
26 Correct 43 ms 5144 KB Output is correct
27 Correct 39 ms 5144 KB Output is correct
28 Correct 36 ms 5144 KB Output is correct
29 Correct 39 ms 5144 KB Output is correct
30 Correct 29 ms 5144 KB Output is correct
31 Correct 0 ms 5144 KB Output is correct
32 Correct 0 ms 5144 KB Output is correct