Submission #1155438

#TimeUsernameProblemLanguageResultExecution timeMemory
1155438SangGap (APIO16_gap)C++20
70 / 100
44 ms1732 KiB
#ifndef _Pbrngw_
#include "gap.h"
#endif // _Pbrngw_
#include<bits/stdc++.h>
using namespace std;

#define FOR(i, a, b) for (int i = (a), _b = (b); i <= _b; i++)
#define FORD(i, a, b) for (int i = (a), _b = (b); i >= _b; i--)
#define fi first
#define se second
#define pb push_back
#define ALL(a) (a).begin(), (a).end()
#define task "kbsiudthw"

typedef vector<int> vi;
typedef pair<int, int> ii;
typedef pair<int, ii> pii;

const int N = 1e5 + 5;
const int INF = 0x3f3f3f3f;
const int MOD = 1e9 + 2277;


long long findGap(int T, int N)
{
    if (T == 1){
        vi A;
        long long x = 0, y = 1e18;
        MinMax(0, 1e18, &x, &y);
        A.pb(x); A.pb(y);
        while (y - x > 1){
            MinMax(x+1, y - 1,  &x, &y);
            if(x == -1) break;
            A.pb(x);
            if (x != y)
                A.pb(y);
        }
        sort(ALL(A));
        int ans = 0;
        FOR  (i, 0, N - 2) ans = max(ans, A[i+1] - A[i]);
        return ans;
    }
    long long A, B, C1, C2;
    MinMax(0, 1e18, &A, &B);
    if (N == 2) return B - A;
    long long block = (B - A - 1)/(N - 2);
    if ((B - A - 1)%(N-2)) ++block;
    long long last = A, ans = 0;
    for (long long i = A+1; i < B; i += block){
        long long x, y;
        MinMax(i, min(B - 1, i + block - 1), &x, &y);
        if (x == -1) continue;
        ans = max(ans, x - last);
        last = y;
    }
    ans = max(ans, B - last);
    return ans;
}

#ifdef _Pbrngw_
signed main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    if (fopen(task".inp", "r")){
        freopen(task".inp", "r", stdin);
        freopen(task".out", "w", stdout);
    }

    return 0;
}
#endif // _Pbrngw_

#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...