제출 #394452

#제출 시각아이디문제언어결과실행 시간메모리
394452VictorGap (APIO16_gap)C++17
100 / 100
68 ms1884 KiB
#include "gap.h"
#include <bits/stdc++.h>

using namespace std;

#define rep(i, a, b) for (int i = a; i < (b); ++i)
#define per(i, a, b) for (int i = b - 1; i >= (a); --i)
#define trav(a, x) for (auto &a : x)

#define all(x) x.begin(), x.end()
#define sz(x) x.size()
#define pb push_back

#define umap unordered_map
#define uset unordered_set

typedef pair<int, int> ii;
typedef pair<int, ii> iii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<vi> vvi;
typedef long long ll;

const int INF = 1000000007;

ll findGap(int t, int n) {
    ll ans = 0, lo, hi;
    MinMax(0, 1e18, &lo, &hi);

    if (t == 1) {
        ll arr[n];
        arr[0] = lo;
        arr[n - 1] = hi;

        rep(i, 0, (n - 1) / 2) {
            ll lotemp, hitemp;
            MinMax(lo + 1, hi - 1, &lotemp, &hitemp);
            lo = lotemp;
            hi = hitemp;

            arr[i + 1] = lo;
            arr[n - i - 2] = hi;
        }

        rep(i, 0, n - 1) ans = max(ans, arr[i + 1] - arr[i]);

    } else {
        ll gap = (hi - lo + n - 2) / (n - 1), curr = lo, pos = curr,guess=1;
        
        while (curr != hi) {
            pos+=gap;
            ll next;
            MinMax(curr + 1, pos, &lo, &next);
            ++guess;
            
            if(next!=-1) {
                ans = max(ans, lo - curr);
                curr = next;
            }
        }
    }

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