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 <bits/stdc++.h>
using namespace std;
#include "gap.h"
using ll = long long;
ll findGap(int T, int N){
if (T == 1){
ll mn, mx;
vector<ll> L, R;
ll lb = -1, rb = (ll)1e18 + 1;
while (N > 0 && lb + 1 <= rb - 1){
MinMax(lb + 1, rb - 1, &mn, &mx);
if (mn < 0) break;
L.push_back(mn); R.push_back(mx);
N--; if (mn != mx) N--;
lb = mn; rb = mx;
}
ll res = 0;
for (int i = 1; i < (int)L.size(); i++){
res = max(res, abs(L[i] - L[i-1]));
}
for (int i = 1; i < (int)R.size(); i++){
res = max(res, abs(R[i] - R[i-1]));
}
res = max(res, abs(R.back() - L.back()));
return res;
}
else{
ll mn, mx;
MinMax(0, (ll)1e18, &mn, &mx);
ll d = mx - mn;
ll st = mn + 1;
vector<pair<ll, ll>> v(N);
for (int i = 0; i < N; i++){
ll dist = d/N + (i < d%N);
v[i] = {st, st + dist - 1};
st += dist;
}
ll res = 0, lst = mn;
for (int i = 0; i < N; i++){
if (v[i].first <= v[i].second){
ll a, b;
MinMax(v[i].first, v[i].second, &a, &b);
if (a < 0) continue;
res = max(res, a - lst);
res = max(res, b - a);
lst = b;
}
}
return res;
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |