Submission #838560

# Submission time Handle Problem Language Result Execution time Memory
838560 2023-08-27T11:38:51 Z tch1cherin Gap (APIO16_gap) C++17
47.6762 / 100
108 ms 3048 KB
#include "gap.h"
#include <bits/stdc++.h>
using namespace std;

long long findGap(int T, int N) {
	if (T == 1) {
		long long Min = -1, Max = 1e18l + 1;
		vector<long long> front, back;
		for (int i = 0; i < (N + 1) / 2; i++) {
			MinMax(Min + 1, Max - 1, &Min, &Max);
			if (Min != Max) {
				front.push_back(Min);
			}
			back.push_back(Max);
		}
		reverse(back.begin(), back.end());
		vector<long long> A;
		for (auto v : front) {
			A.push_back(v);
		}
		for (auto v : back) {
			A.push_back(v);
		}
		long long gap = 0;
		for (int i = 0; i < N - 1; i++) {
			gap = max(gap, A[i + 1] - A[i]);
		}
		return gap;
	} else {
		long long Min, Max;
		MinMax(0, 1e18, &Min, &Max);
		priority_queue<tuple<long double, long long, long long>> Q;
		Q.push({1, Min, Max});
		long long maxConfirmed = (Max - Min + N - 2) / (N - 1);
		uniform_real_distribution<long double> dist(0, 1);
		mt19937 rng(chrono::steady_clock().now().time_since_epoch().count());
		while (!Q.empty()) {
			auto [p, l, r] = Q.top();
			Q.pop();
			if (r - l <= maxConfirmed) {
				continue;
			}
			long long mid = l + (r - l) / 2;
			long long Minl = -1, Maxl = -1, Minr = -1, Maxr = -1;
			if (l <= mid) {
				MinMax(l, mid, &Minl, &Maxl);
				if (Minl != -1 && mid - l > maxConfirmed) {
					Q.push({(Maxl - Minl) * dist(rng), Minl, Maxl});
				}
			}
			if (mid + 1 <= r) {
				MinMax(mid + 1, r, &Minr, &Maxr);
				if (Minr != -1 && r - mid - 1 > maxConfirmed) { 
					Q.push({(Maxl - Minl) * dist(rng), Minr, Maxr});
				}
			}
			if (Maxl != -1 && Minr != -1) {
				maxConfirmed = max(maxConfirmed, Minr - Maxl);
			}
		}
		return maxConfirmed;
	}
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 208 KB Output is correct
2 Correct 0 ms 208 KB Output is correct
3 Correct 0 ms 208 KB Output is correct
4 Correct 0 ms 208 KB Output is correct
5 Correct 0 ms 208 KB Output is correct
6 Correct 0 ms 208 KB Output is correct
7 Correct 0 ms 208 KB Output is correct
8 Correct 0 ms 208 KB Output is correct
9 Correct 0 ms 208 KB Output is correct
10 Correct 0 ms 208 KB Output is correct
11 Correct 1 ms 336 KB Output is correct
12 Correct 1 ms 336 KB Output is correct
13 Correct 1 ms 336 KB Output is correct
14 Correct 1 ms 336 KB Output is correct
15 Correct 1 ms 336 KB Output is correct
16 Correct 7 ms 1144 KB Output is correct
17 Correct 7 ms 1184 KB Output is correct
18 Correct 7 ms 1124 KB Output is correct
19 Correct 7 ms 1168 KB Output is correct
20 Correct 6 ms 1104 KB Output is correct
21 Correct 29 ms 3048 KB Output is correct
22 Correct 33 ms 2940 KB Output is correct
23 Correct 29 ms 2980 KB Output is correct
24 Correct 29 ms 3032 KB Output is correct
25 Correct 28 ms 2968 KB Output is correct
26 Correct 29 ms 3028 KB Output is correct
27 Correct 29 ms 2964 KB Output is correct
28 Correct 30 ms 2992 KB Output is correct
29 Correct 29 ms 2960 KB Output is correct
30 Correct 24 ms 2968 KB Output is correct
31 Correct 0 ms 208 KB Output is correct
32 Correct 0 ms 208 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 208 KB Output is correct
2 Partially correct 0 ms 208 KB Partially correct
3 Partially correct 0 ms 208 KB Partially correct
4 Correct 0 ms 208 KB Output is correct
5 Partially correct 0 ms 208 KB Partially correct
6 Partially correct 0 ms 220 KB Partially correct
7 Partially correct 0 ms 208 KB Partially correct
8 Partially correct 0 ms 208 KB Partially correct
9 Partially correct 0 ms 208 KB Partially correct
10 Partially correct 0 ms 208 KB Partially correct
11 Partially correct 1 ms 336 KB Partially correct
12 Partially correct 1 ms 336 KB Partially correct
13 Partially correct 1 ms 336 KB Partially correct
14 Partially correct 1 ms 336 KB Partially correct
15 Partially correct 1 ms 336 KB Partially correct
16 Partially correct 8 ms 592 KB Partially correct
17 Partially correct 10 ms 616 KB Partially correct
18 Partially correct 7 ms 544 KB Partially correct
19 Partially correct 7 ms 592 KB Partially correct
20 Partially correct 3 ms 464 KB Partially correct
21 Partially correct 30 ms 1220 KB Partially correct
22 Partially correct 27 ms 1336 KB Partially correct
23 Partially correct 24 ms 1200 KB Partially correct
24 Partially correct 30 ms 1188 KB Partially correct
25 Partially correct 108 ms 2164 KB Partially correct
26 Partially correct 26 ms 1368 KB Partially correct
27 Partially correct 30 ms 1184 KB Partially correct
28 Partially correct 28 ms 1340 KB Partially correct
29 Partially correct 25 ms 1232 KB Partially correct
30 Partially correct 9 ms 1060 KB Partially correct
31 Correct 0 ms 208 KB Output is correct
32 Correct 0 ms 208 KB Output is correct