| # | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 | 
|---|---|---|---|---|---|---|---|
| 770630 | Enchom | Gap (APIO16_gap) | C++14 | 0 ms | 0 KiB | 
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <iostream>
#include <stdio.h>
#include <vector>
#include "gap.h"
using namespace std;
typedef long long llong;
const llong MAXVAL = 1000000000000000000LL;
llong solveSmall(int N)
{
    llong minVal, maxVal;
    llong L = 0, R = MAXVAL;
    int pL = 0, pR = N - 1;
    vector<llong> nums(N);
    while(pL <= pR)
    {
        MinMax(L, R, &minVal, &maxVal);
        nums[pL] = minVal;
        nums[pR] = maxVal;
        pL++;
        pR--;
        L = minVal + 1;
        R = maxVal - 1;
    }
    llong ans = 0;
    for (int i = 1; i < nums.size(); i++)
    {
        ans = max(ans, nums[i] - nums[i - 1]);
    }
    return ans;
}
llong solveBig(int N)
{
    llong minVal, maxVal;
    llong curVal, endVal;
    llong bestGap = 0;
    MinMax(0, MAXVAL, &curVal, &endVal);
    llong curGap = (endVal - curVal) / (N - 1);
    if ( (endVal - curVal) % (N - 1) != 0 )
        curGap++;
    curGap--;
    bestGap = curGap;
    while(curVal != endVal)
    {
        MinMax(curVal + 1, curVal + curGap, minVal, maxVal);
        if (minVal == -1)
        {
            bestGap = max(bestGap, curGap);
            curGap = curGap * 2 + 2;
        }
        else
        {
            bestGap = max(bestGap, minVal - curVal);
            curGap = bestGap;
            curVal = maxVal;
        }
    }
    return bestGap;
}
llong findGap(int T, int N)
{
    if (T == 1)
        return solveSmall(N);
    else
        return solveBig(N);
}
/*
int main()
{
}
*/
