Submission #381917

#TimeUsernameProblemLanguageResultExecution timeMemory
381917ijxjdjdGap (APIO16_gap)C++14
100 / 100
63 ms2028 KiB
#include "gap.h"
#include <bits/stdc++.h>
using ll = long long;

long long findGap(int T, int N)
{

    if (T == 1) {
        ll low = 0;
        ll high = (ll)(1e18);
        ll arr[N];
        int l = 0;
        int r = N-1;
        while (l <= r) {
            MinMax(low, high, &low, &high);
            arr[l++] = low;
            arr[r--] = high;
            low++;
            high--;
        }
        ll mx = 0;
        for (int i = 1; i < N; i++) {
            mx = std::max(mx, arr[i] - arr[i-1]);
        }
        return mx;
    }
    else {
        ll first = 0;
        ll last = 0;
        MinMax(first, (ll)(1e18), &first, &last);
        ll d = (last-first + N-2)/(N-1);
        ll ans = 0;
        ll next = first+d;
        first++;
        while (first < last) {
            ll mn, mx;
            MinMax(first, next, &mn, &mx);
            if (mn != -1) {
                ans = std::max(mn - (first-1), ans);
                first = mx+1;
            }
            next += d;
        }
        return ans;
    }
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...