Submission #1083372

#TimeUsernameProblemLanguageResultExecution timeMemory
1083372dong_gasGap (APIO16_gap)C++17
36.46 / 100
66 ms4348 KiB
#include <bits/stdc++.h>

#include "gap.h"

using namespace std;
using ll = long long;
using pll = pair<ll, ll>;

ll a[100201];
ll l[100201], r[100201];
pll b[100201];
const ll inf = 1'000'000'000'000'000'000;

ll findGap(int T, int n) {
    ll mn, mx, ret = 0;
    MinMax(0, inf, &mn, &mx);
    a[1] = mn, a[n] = mx;
    ll gap = (mx - mn + 1) / n;
    for (ll i = a[1], cnt = 1; cnt <= n; i += gap, cnt++) {
        l[cnt] = i, r[cnt] = i + gap - 1;
        if (cnt == n) r[cnt] = a[n];
    }
    bool full = true;
    for (int i = 1; i <= n; i++) {
        MinMax(l[i], r[i], &mn, &mx);
        b[i] = {mn, mx};
        if (mn == -1) full = false;
    }
    if (full) {
        for (int i = 2; i <= n; i++) {
            ret = max(ret, b[i].first - b[i - 1].first);
        }
    } else {
        ll bef = -1;
        for (int i = 1; i <= n; i++) {
            if (b[i].first == -1) continue;
            if(bef!=-1) {
                MinMax(bef, b[i].first, &mn, &mx);
                ret = max(ret, mx - mn);
            }            
            bef = b[i].second;
        }

    }
    return ret;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...