Submission #154772

#TimeUsernameProblemLanguageResultExecution timeMemory
154772MercenaryGap (APIO16_gap)C++14
0 / 100
83 ms3832 KiB
#include<bits/stdc++.h>

#include "gap.h"
using namespace std;
typedef long long ll;

const int maxn = 1e5 + 6;
ll a[maxn];
long long findGap(int T, int N)
{
    int n = N;
    if(T == 1){
        ll u = 0 - 1 , v = 1e18 + 1;
        for(int i = 1 , j = n ; i <= j ; ++i , --j){
            MinMax(u + 1 , v - 1 , &a[i] , &a[j]);
            u = a[i] , v = a[j];
        }
        ll res = 0;
        for(int i = 2 ; i <= n ; ++i){
            res = max(res , a[i] - a[i - 1]);
        }
        return res;
    }
    else{
        ll u = 0 , v = 1e18;
        MinMax(u , v , &u , &v);
        ll gap = (v - u) / (n - 1);
        a[1] = u;
        ll res = 0;
        for(int i = 2 ; i <= n ; ++i){
            MinMax(a[i - 1] , a[i - 1] + gap , &a[i - 1] , &a[i]);
            if(a[i] == a[i - 1])a[i] = a[i - 1] + 1;
        }
        a[n] = v;
        for(int i = 2 ; i <= n ; ++i)res = max(res , a[i] - a[i - 1]);
        return res;
    }
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...