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;
long long findGap(int t, int n) {
vector<long long> a(n + 1);
if (t == 1) {
long long mi = - 1, ma = 1e18 + 1;
int l = 1;
int r = n;
while (l <= r) {
MinMax(mi + 1, ma - 1, &mi, &ma);
a[l] = mi, a[r] = ma;
l++, r--;
}
long long ans = 0;
for (int i = 2; i <= n; i++) ans = max(ans, a[i] - a[i - 1]);
return ans;
}
long long ans = 0;
long long mi = - 1, ma = 1e18 + 1;
MinMax(mi + 1, ma - 1, &mi, &ma);
long long maxx = ma;
long long res = (ma - mi) / (n - 1);
ma = mi;
do {
long long cur_mi = mi;
MinMax(mi + 1, ma + res, &mi, &ma);
if (ma == - 1) {
ans = max(ans, mi - cur_mi);
ma = mi;
}
else {
if (mi == ma) ans = max(ans, mi - cur_mi);
mi = ma;
}
} while (mi != - 1);
return ans;
}
Compilation message (stderr)
gap.cpp: In function 'long long int findGap(int, int)':
gap.cpp:24:15: warning: unused variable 'maxx' [-Wunused-variable]
24 | long long maxx = ma;
| ^~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |