Submission #399180

#TimeUsernameProblemLanguageResultExecution timeMemory
399180dxz05Gap (APIO16_gap)C++14
30 / 100
74 ms1872 KiB
#include "gap.h"
#include <bits/stdc++.h>

using namespace std;

const int MAXN = 555555;

typedef long long ll;
ll a[MAXN];

long long findGap(int SUBTASK, int n){
    if (SUBTASK == 1){
        ll mn = 0, mx = 1e18;
        for (int i = 1; i <= (n + 1) / 2; i++){
            MinMax(mn, mx, &a[i], &a[n - i + 1]);
            mn = a[i] + 1;
            mx = a[n - i + 1] - 1;
        }
    } else {
        a[0] = -1;
        for (int i = 1; i <= n; i++){
            ll l = a[i - 1] + 1, r = 1e18;
                while (l <= r){
                ll m = (l + r) >> 1;

                ll mn, mx;

                MinMax(a[i - 1] + 1, m, &mn, &mx);
                if (mn != -1){
                    a[i] = mn;
                    break;
                }

                l = m + 1;
            }
        }
    }

    ll ans = 0;
    for (int i = 1; i < n; i++){
        ans = max(ans, a[i + 1] - a[i]);
    }

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