# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
554165 | QwertyPi | Gap (APIO16_gap) | C++14 | 0 ms | 0 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "gap.h"
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
long long findGap(int T, int N)
{
if(T == 1){
ll L = -1, R = 1e18+1;
set<ll> a;
for(int j = 0; j < (N + 1) / 2; j++){
MinMax(L + 1, R - 1, &L, &R);
if(L != -1) a.insert(L); if(R != -1) a.insert(R);
}
ll ans = 0;
for(auto it = a.begin(); it != a.end(); it++){
if(next(it) != a.begin()) ans = max(ans, *next(it) - *it);
}
}else{
ll L, R;
MinMax(0, 1e18, &L, &R);
ll tg = 1 + (R - L - 1) / (N - 1);
set<ll> a; a.insert(L); a.insert(R);
for(ll i = L + 1; i < R; i += tg){
ll ll, rr;
MinMax(i, min(R - 1, i + tg - 1), &ll, &rr);
if(ll != -1) a.insert(ll); if(rr != -1) a.insert(rr);
}
ll ans = 0;
for(auto it = a.begin(); it != a.end(); it++){
if(next(it) != a.begin()) ans = max(ans, *next(it) - *it);
}
}
return ans;
}