Submission #736449

#TimeUsernameProblemLanguageResultExecution timeMemory
736449Jarif_RahmanGap (APIO16_gap)C++17
53.51 / 100
57 ms1112 KiB
#include "gap.h"
#include <bits/stdc++.h>
#define pb push_back
#define f first
#define sc second
using namespace std;
typedef long long int ll;
typedef string str;

ll findGap(int T, int n){
    if(T == 1){
        ll ans = 0, a, b;
        MinMax(0, 1e18, &a, &b);
        while(a+1 < b){
            ll _a, _b;
            MinMax(a+1, b-1, &_a, &_b);
            if(_a == -1) break;
            ans = max(ans, max(_a-a, b-_b));
            swap(a, _a), swap(b, _b);
        }
        ans = max(ans, b-a);
        return ans;
    }
    ll ans = 0, a, b;
    MinMax(0, 1e18, &a, &b);
    ll k = (b-a+n-2)/(n-1);

    ll prev = a;
    int cnt = 0;
    for(ll i = a; i <= b; i+=k){
        cnt++;
        ll x, y;
        MinMax(i, min(i+k-1, b), &x, &y);
        if(x == -1) continue;
        ans = max(ans, x-prev);
        prev = y;
    }
    assert(cnt <= n);
    return ans;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...