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>
using namespace std;
long long x[100009];
const long long xmax = 1e18;
long long rand15 () {return rand () & 32767;}
long long rand30 () {return (rand15 () << 15LL) | rand15 ();}
long long rand60 () {return (rand30 () << 30LL) | rand30 ();}
long long findGap(int T, int N)
{
srand (time (0));
if (T == 1)
{
long long a = 0, b = xmax;
for (int i = 1, j = N; i<=j; i ++, j --)
MinMax (a, b, &x[i], &x[j]), a = x[i] + 1, b = x[j] - 1;
long long ans = x[2] - x[1];
for (int i=1; i<N; i++)
if (x[i + 1] - x[i] > ans)
ans = x[i + 1] - x[i];
return ans;
}
long long mi, ma;
MinMax (0, xmax, &mi, &ma);
long long L = (ma - mi) / (N - 1) + ((ma - mi) % (N - 1) != 0);
int nr = 0;
long long st = mi + 1;
x[1] = mi, nr = 1;
while (st < ma)
{
long long dr = st + L - 1, y, z;
if (dr >= ma) dr = ma - 1;
MinMax (st, dr, &y, &z);
if (y != -1) x[++nr] = y;
if (y != z) x[++nr] = z;
st = dr + 1;
}
x[++nr] = ma;
long long ans = x[2] - x[1];
for (int i=2; i<nr; i++)
ans = max (ans, x[i + 1] - x[i]);
return ans;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |