Submission #1324418

#TimeUsernameProblemLanguageResultExecution timeMemory
1324418tamzidGap (APIO16_gap)C++20
30 / 100
2110 ms589824 KiB
#include <bits/stdc++.h>
#include "gap.h"
using namespace std;
using ll = long long;

long long findGap(int T, int N)
{
    if(T == 1) {
        vector<ll> a(N);
        ll l = 0, r = 1e18;
        int i = 0, j = N - 1;
        while(i <= j) {
            ll mn, mx;
            MinMax(l, r, &mn, &mx);
            a[i] = mn;
            a[j] = mx;
            l = mn + 1;
            r = mx - 1;
            ++i;
            --j;
        }
        ll ans = 0;
        for(int i=0;i<N-1;++i)
            ans = max(ans, a[i + 1] - a[i]);
        return ans;
    } else {
        vector<ll> a;
        ll mn, mx;
        MinMax(0, 1e18, &mn, &mx);
        a.push_back(mn);
        a.push_back(mx);
        ll l = mn, r = mx;
        ++l;
        --r;
        ll gaps = (mx - mn + (N - 2) - 1) / (N - 2);
        ll st = l, en;
        while(st < r && a.size() < N) {
            en = min(r, st + (gaps - 1));
            bool f = true, f1 = false;
            mn = -1, mx = -1;
            while(st <= en && (f || (!f && !f1))) {
                MinMax(st, en, &mn, &mx);
                if(mn != -1) {
                    a.push_back(mn);
                    if(mx != mn) {
                        a.push_back(mx);
                        f1 = true;
                    } else {
                        f1 = false;
                    }
                } else {
                    f1 = false;
                }   
                f = true;
            }
            st += gaps;
        }
        sort(a.begin(), a.end());
        ll ans = 0;
        for(int i=0;i<N-1;++i) {
            ans = max(ans, a[i + 1] - a[i]);
        }
        return ans;
    }
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...