제출 #1187559

#제출 시각아이디문제언어결과실행 시간메모리
1187559trvhungGap (APIO16_gap)C++20
100 / 100
43 ms1864 KiB
#include "gap.h"
#include <bits/stdc++.h>
// #include <ext/rope>
// #include <ext/pb_ds/assoc_container.hpp>

// using namespace __gnu_pbds;
// using namespace __gnu_cxx;
using namespace std;

// #define   ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define            ll long long
#define           ull unsigned long long
#define            ld long double
#define            pb push_back
#define  bit(mask, i) ((mask >> i) & 1)
#define            el '\n'
#define             F first
#define             S second

template <class X, class Y> bool maximize(X &x, const Y &y) { return (x < y ? x = y, 1 : 0); }
template <class X, class Y> bool minimize(X &x, const Y &y) { return (x > y ? x = y, 1 : 0); }

const int INF = 1e9;
const ll LINF = 1e18;
const int MOD = 1e9 + 7;
const int MULTI = 0;
const ld eps = 1e-9;
const int dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0}; // R D L U
const int ddx[4] = {-1, 1, 1, -1}, ddy[4] = {1, 1, -1, -1}; // UR DR DL UL
const char cx[4] = {'R', 'D', 'L', 'U'};
const ll base = 31;
const int nMOD = 2;
const ll mods[] = {(ll)1e9 + 10777, (ll)1e9 + 19777, (ll)1e9 + 3, (ll)1e9 + 3777};

const int maxn = 1e5 + 5;
int n;
ll a[maxn];

ll solve1() {
	ll limL = 0, limR = LINF, mn, mx;
	int i = 1, j = n;

	while (i <= j) {
		MinMax(limL, limR, &mn, &mx);
		a[i] = mn; a[j] = mx;
		limL = a[i] + 1;
		limR = a[j] - 1;
		i++; j--;
	}

	ll res = 0;
	for (int i = 1; i < n; ++i)
		maximize(res, a[i + 1] - a[i]);

	return res;
}

ll solve2() {
	ll mn, mx;
	MinMax(0, LINF, &mn, &mx);
	
	ll block_size = (mx - mn + n - 2) / (n - 1);
	ll res = block_size, x, y, bef = mn, i;

	for (i = mn; i + block_size < mx; i += block_size + 1) {
		MinMax(i, i + block_size, &x, &y);
		if (x != -1) {
			maximize(res, x - bef);
			bef = y;
		}
	}

	MinMax(i, mx, &x, &y);
	if (x != -1) maximize(res, x - bef);

	return res;
}

ll findGap(int T, int N) {
	n = N;
	return (T == 1 ? solve1() : solve2());
}

// signed main() {
//     ios_base::sync_with_stdio(0);
//     cin.tie(0); cout.tie(0);

//     #ifndef ONLINE_JUDGE
//     freopen("input.inp", "r", stdin);
//     freopen("output.out", "w", stdout);
//     #endif

//     if (!MULTI) solve();
//     else {
//         int test; cin >> test;
//         while (test--) solve();
//     }
    
//     return 0;
// }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...