제출 #1149739

#제출 시각아이디문제언어결과실행 시간메모리
1149739vladiliusGap (APIO16_gap)C++20
100 / 100
44 ms1960 KiB
#include <bits/stdc++.h>
#include "gap.h"
using namespace std;
using ll = long long;
using pii = pair<int, int>;
#define pb push_back
#define ff first
#define ss second
const ll inf = 1e18;

ll findGap(int T, int n){
    if (T == 1){
        ll l, r, s = 0, t = inf;
        vector<ll> a(n);
        for (int i = 0; i < (n + 1) / 2; i++){
            MinMax(s, t, &l, &r);
            a[i] = l; a[n - i - 1] = r;
            s = l + 1; t = r - 1;
        }
        ll out = 0;
        for (int i = 0; i < (n - 1); i++){
            out = max(out, a[i + 1] - a[i]);
        }
        return out;
    }
    ll l, r;
    MinMax(0, inf, &l, &r);
    if ((r - l + 1) == n) return 1;
    ll M = r, f = ceil(1.0 * (r - l) / (n - 1)), k = l, P = k, out = 0;
    while (k < M){
        MinMax(k + 1, k + f, &l, &r);
        if (l != -1){
            out = max(out, l - P);
            P = r;
        }
        k += f;
    }
    out = max(out, (M - P));
    return out;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...