Submission #344066

#TimeUsernameProblemLanguageResultExecution timeMemory
344066milleniumEeeeGap (APIO16_gap)C++17
30 / 100
86 ms3428 KiB
#include "gap.h"
//#include "grader.cpp"
#include <bits/stdc++.h>
#define ll long long
using namespace std;
 
//MinMax(long long s, long long t, long long *mn, long long *mx)
 
const ll INF = (ll)1e18;
const int MAXN = (int)1e5 + 5;
 
ll a[MAXN];
vector <ll> order;

ll get_mid(ll l, ll r) {
  return (l + r) >> 1ll;
}

void build(ll l, ll r) {
  if (l > r) {
    return;
  }
  ll mn, mx;
  MinMax(l, r, &mn, &mx);
  if (mn == -1 && mx == -1) {
    return;
  } else {
    if (mn != mx) {
      order.push_back(mn);
      order.push_back(mx);
      ll mid = get_mid(mn + 1, mx - 1);
      build(mn + 1, mid);
      build(mid + 1, mx);
    } else {
      order.push_back(mn);
      return;
    }
  }
}
 
long long findGap(int type, int n)
{
  if (type == 1) {
    ll mn, mx;
    MinMax(0, INF, &mn, &mx);
    int l = 1, r = n;
    a[l] = mn;
    a[r] = mx;
    while (r - l - 1 >= 2) {
      MinMax(mn + 1, mx - 1, &mn, &mx);
      a[++l] = mn;
      a[--r] = mx;
    }
    if (r - l + 1 == 3) {
      MinMax(mn + 1, mx - 1, &mn, &mx);
      a[l + 1] = mn;
    }
    ll ans = 0;
    for (int i = 1; i < n; i++) {
      ans = max(ans, a[i + 1] - a[i]);
    }
    return ans;
  } else {
    build(0, INF);
    sort(order.begin(), order.end());
    ll ans = 0;
    for (int i = 0; i + 1 < n; i++) {
      ans = max(ans, order[i + 1] - order[i]);
    }
    return ans;
  }
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...