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 <cstdio>
#include <algorithm>
using namespace std;
typedef long long ll;
const ll MIN = 0, MAX = 1000000000000000000;
ll solve1(int n) {
ll v[n+1];
int i = 1, k = n;
ll mn = MIN, mx = MAX;
while (i <= k) {
MinMax(mn, mx, v+i, v+k);
mn = v[i++]+1;
mx = v[k--]-1;
}
ll ret = 1;
for (int i = 1; i < n; i++)
ret = max(ret, v[i+1] - v[i]);
return ret;
}
ll solve2(int n) {
ll cur, lim;
MinMax(MIN, MAX, &cur, &lim);
ll ans = 1, test, l, r;
while (cur < lim) {
test = 0;
do MinMax(cur+1+test*ans, cur+1+(test+1)*ans, &l, &r), test++;
while (l == -1);
ans = max(ans, l - cur);
cur = r;
}
return ans;
}
ll findGap(int t, int n)
{
return t == 1 ? solve1(n) : solve2(n);
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |