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 "grader.cpp"
#include <bits/stdc++.h>
#define ll long long
using namespace std;
//MinMax(long long s, long long t, long long *mn, long long *mx)
const ll INF = (ll)1e18;
const int MAXN = (int)1e5 + 5;
ll a[MAXN];
long long findGap(int type, int n)
{
if (n == 2) {
ll mn, mx;
MinMax(0, INF, &mn, &mx);
return mx - mn;
}
if (type == 1) {
ll mn, mx;
MinMax(0, INF, &mn, &mx);
int l = 1, r = n;
a[l] = mn;
a[r] = mx;
while (r - l - 1 >= 2) {
MinMax(mn + 1, mx - 1, &mn, &mx);
a[++l] = mn;
a[--r] = mx;
}
if (r - l + 1 == 3) {
MinMax(mn + 1, mx - 1, &mn, &mx);
a[l + 1] = mn;
}
ll ans = 0;
for (int i = 1; i < n; i++) {
ans = max(ans, a[i + 1] - a[i]);
}
return ans;
} else {
ll ans = 0;
ll mn, mx;
vector <ll> arr;
MinMax(0, INF, &mn, &mx);
ll k = (mx - mn - 1) / (n - 1ll);
arr.push_back(mn);
arr.push_back(mx);
ll MN = mn, MX = mx;
for (ll pos = MN + 1; pos <= MX - 1; pos += k) {
ll l = pos;
ll r = min(MX - 1, pos + k - 1);
MinMax(l, r, &mn, &mx);
if (mn != -1 && mx != -1) {
if (mn == mx) {
arr.push_back(mn);
} else {
arr.push_back(mn);
arr.push_back(mx);
}
}
}
sort(arr.begin(), arr.end());
for (int i = 0; i + 1 < (int)arr.size(); i++) {
ans = max(ans, arr[i + 1] - arr[i]);
}
return ans;
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |