| # | Time | Username | Problem | Language | Result | Execution time | Memory |
|---|---|---|---|---|---|---|---|
| 1328303 | nguyenkhangninh99 | Gap (APIO16_gap) | C++20 | 0 ms | 0 KiB |
#include "gap.h"
#include <bits/stdc++.h>
using namespace std;
#define ll long long
ll findGap(int t, int n){
ll ans = 0;
if(t == 1){
vector<ll> a;
ll l = 1, r = 1e18, mn, mx;
while(a.size() < n){
MinMax(l, r, &mn, &mx);
if(mn == -1) break;
a.push_back(mn);
a.push_back(mx);
l = mn + 1;
r = mx - 1;
}
sort(a.begin(), a.end());
for(int i = 0; i + 1 < a.size(); i++) ans = max(ans, a[i + 1] - a[i]);
}else{
ll st = INF, en = -INF;
MinMax(0, INF, &st, &en);
ll X = (en - st + N - 2) / (N - 1);
ll x = st;
ll premx = -1;
ans = X;
int cnt = 0;
while(x <= en){
cnt++;
ll mn = INF, mx = -INF, nxx = x + X;
MinMax(x, nxx, &mn, &mx);
if(premx != -1 && mx != -1) ans = max(ans, mn - premx);
if(mx != -1) premx = mx;
x = nxx + 1;
}
}
return ans;
}