제출 #736453

#제출 시각아이디문제언어결과실행 시간메모리
736453Jarif_RahmanGap (APIO16_gap)C++17
100 / 100
56 ms1204 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);
        for(int i = 0; i < (n+1)/2-1; i++){
            ll x, y;
            MinMax(a+1, b-1, &x, &y);
            ans = max(ans, max(x-a, b-y));
            a = x, b = y;
        }
        if(n%2 == 0) 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;
        if(i == b) x = b, y = b;
        else 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...