제출 #771027

#제출 시각아이디문제언어결과실행 시간메모리
771027boris_mihovGap (APIO16_gap)C++17
100 / 100
48 ms1868 KiB
#include "gap.h"
#include <algorithm>
#include <iostream>
#include <numeric>
#include <vector>

typedef long long llong;
const int MAXN = 100000 + 10;
const int INF  = 1e9;
    
int n;
llong a[MAXN];
llong findGap(int T, int N)
{
    n = N;
    if (T == 1)
    {
        int lPtr = 1;
        int rPtr = n;
        llong lLast = 0;
        llong rLast = 1e18;
        while (lPtr <= rPtr)
        {
            MinMax(lLast, rLast, &lLast, &rLast);
            a[lPtr++] = lLast;
            a[rPtr--] = rLast;
            lLast++; rLast--;
        }

        llong max = 0;
        for (int i = 1 ; i < n ; ++i)
        {
            max = std::max(max, a[i + 1] - a[i]);
        }

        return max;
    }

    llong ans = 1;
    llong min, max;
    MinMax(0, (llong)1e18, &min, &max);
    llong gap = ((max - min + 1) / n + (((max - min + 1) % n) > 0)) * 2 - 1;

    llong last = min;
    while (last < max)
    {
        llong currMin, currMax;
        MinMax(last + 1, last + gap, &currMin, &currMax);
        if (currMin == -1)
        {
            gap *= 2;
            continue;
        }
        
        gap = currMin - last;
        ans = std::max(ans, gap);
        last = currMax;
    }

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