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>
#include "gap.h"
using namespace std;
typedef long long ll;
long long findGap(int t, int n)
{
ll lo = 0, hi = (ll)1e18;
if (t == 1) {
ll le = 0, ri = n-1, x, y;
vector<ll> a(n);
while (le <= ri) {
MinMax(lo,hi,&x,&y);
if (x == -1) break;
a[le] = x;
a[ri] = y;
lo = x+1;
hi = y-1;
le++;
ri--;
}
ll ans = 0;
for (int q = 1; q < n; q++) {
ans = max(ans, a[q]-a[q-1]);
}
return ans;
} else {
ll x,y;
MinMax(lo,hi,&x,&y);
if (n == 2) return y-x;
ll piece = (y-x-1)/(n-1);
ll add = y-x-1-(n-1)*piece;
vector<pair<ll,ll>> inter;
ll last = x;
for (int q = 0; q < n-1; q++) {
inter.emplace_back(last+1,last+1+piece);
if (add > 0) inter.back().second++;
last = inter.back().second;
}
ll a,b;
vector<pair<ll,ll>> res;
for (int q = 0; q < n-1; q++) {
MinMax(inter[q].first,inter[q].second,&a,&b);
res.emplace_back(a,b);
}
ll ans = 0;
last = x;
for (int q = 0; q < n-1; q++) {
if (res[q].first == -1) continue;
ans = max(ans, res[q].first-last);
ans = max(ans, res[q].second-res[q].first);
last = res[q].second;
}
ans = max(ans, y-last);
return ans;
}
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |