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>
#define ll long long
#define endl "\n"
using namespace std;
ll findGap(int t, int n)
{
if (t == 1)
{
ll ans = 0;
ll a[n];
ll l = 0, r = 1e18, i = 0, j = n - 1;
while (i <= j)
{
MinMax(l, r, &a[i], &a[j]);
l = a[i++] + 1;
r = a[j--] - 1;
}
for (ll i = 0; i + 1 < n; i++)
ans = max(ans, a[i + 1] - a[i]);
return ans;
}
ll mn, mx;
MinMax(0, 1e18, &mn, &mx);
ll l = (mx - mn + n - 1) / n, r = mx - mn;
while (l <= r)
{
ll mid = (l + r) >> 1, cur = mn, x, y;
bool ok = false;
while (cur + mid <= mx)
{
MinMax(cur + 1, cur + mid - 1, &x, &y);
if (x == -1)
{
ok = true;
break;
}
cur = y;
}
if (ok)
l = mid + 1;
else
r = mid - 1;
}
return --l;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |