제출 #252689

#제출 시각아이디문제언어결과실행 시간메모리
252689ChrisTGap (APIO16_gap)C++17
100 / 100
74 ms1916 KiB
#include<bits/stdc++.h>
using namespace std;
#include "gap.h"
long long findGap (int t, int n) {
  if (t == 1) {
    vector<long long> arr(n+1);
    long long low = -1, high = 1'000'000'000LL * 1'000'000'000LL + 1;
    for (int i = 1; i <= (n+1)/2; i++) {
      MinMax(low+1,high-1,&low,&high);
      arr[i] = low; arr[n-i+1] = high;
    }
    long long mx = 0;
    for (int i = 1; i < n; i++) {
      mx = max(mx,arr[i+1] - arr[i]);
    }
    return mx;
  } else {
    long long mx,mn;
    MinMax(0,1e18,&mn,&mx); 
    long long go = max(1LL,(mx - mn + n - 2) / (n - 1)), ret = 0, lstmx = mn;
    for (long long cur = mn+1; cur < mx; cur += go) {
      long long ed = min(cur + go-1,mx-1);
      long long low,high;
      MinMax(cur,ed,&low,&high);
      if (low != -1) {
        ret = max(ret,low - lstmx);
        lstmx = high;
      }
    }
    ret = max(ret,mx - lstmx);
    return ret;
  }
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...