제출 #249904

#제출 시각아이디문제언어결과실행 시간메모리
249904receedGap (APIO16_gap)C++14
100 / 100
71 ms1172 KiB
#include "gap.h"
#include <vector>
#include <algorithm>
#include <iostream>

using namespace std;
using ll = long long;

ll findGap(int t, int n) {
    ll l, r, x, y, ls;
    MinMax(0, 1'000000'000000'000000, &l, &r);
    if (t == 2) {
        ll ans = (r - l + n - 2) / (n - 1), d = ans;
        ls = l;
        for (int i = 0; i < n - 1; i++) {
            ll lp = l + 1 + d * i, rp = l + d * (i + 1);
            if (lp >= r)
                break;
            rp = min(rp, r);
            MinMax(lp, rp, &x, &y);
            if (y != -1) {
                ans = max(ans, x - ls);
                ls = y;
            }
        }
        ans = max(ans, r - ls);
        return ans;
    }
    else {
        ll ans = 0;
        n -= 2;
        while (n > 0 && r - l > 1) {
            MinMax(l + 1, r - 1, &x, &y);
            if (x == -1) {
                ans = max(ans, r - l);
                break;
            }
            ans = max(ans, x - l);
            ans = max(ans, r - y);
            l = x;
            r = y;
            n -= 2;
        }
        ans = max(ans, r - l);
        return ans;
    }
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...