# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
501365 | kevinxiehk | Gap (APIO16_gap) | C++17 | 0 ms | 0 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#ifdef __cplusplus
extern "C" {
#endif
void MinMax(long long s, long long t, long long* mn, long long* mx);
long long findGap(int T, int N);
#ifdef __cplusplus
}
#endif
// TODO: global variables can be declared here
long long max(long long a, long long b) {
return (a > b ? a : b);
}
long long findGap(int T, int n) {
// TODO: implementation
if(T == 1) {
long long arr[n + 5];
for(int i = 0; i < (n + 1) / 2; i++) {
if(i == 0) MinMax(0, 1000000000000000000LL, &arr[0], &arr[n - 1]);
else MinMax(arr[i - 1] + 1, arr[n - i] - 1, &arr[i], &arr[n - i - 1]);
}
long long ans = 0;
for(int i = 0; i < n - 1; i++) ans = max(ans, arr[i + 1] - arr[i]);
return ans;
}
else {
long long l, r;
MinMax(0, 1000000000000000000LL, &l, &r);
long long chunk = (r - l + n - 2) / (n - 1);
long long a, b, c = l;
l++;
long long ans = 0;
while(l < r) {
MinMax(l, l + chunk - 1, &a, &b);
l += chunk;
if(a == -1) continue;
ans = max(ans, a - c);
c = b;
}
ans = max(ans, r - c);
return ans;
}
}