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;
typedef long long ll;
typedef pair<int, int> pii;
ll findGap(int T, int n) {
ll mn, mx;
ll gap = 0;
pair<ll, ll> range = { 0, 1000000000000000000ll };
vector<ll> arr;
if (T == 1) {
for (int i=0; i<(n+1)/2; ++i) {
MinMax(range.first, range.second, &mn, &mx);
arr.push_back(mn);
arr.push_back(mx);
range = { mn+1, mx-1 };
}
} else {
MinMax(range.first, range.second, &mn, &mx);
arr.push_back(mn);
arr.push_back(mx);
ll d = (mx-mn-1) / (n-1);
ll mn_cpy = mn, mx_cpy = mx;
// cout << d << ' ' << mn << ' ' << mx << endl;
for (int i=0; i<n-1; ++i) {
// cout << mn_cpy+1 + (d+1)*i << ' ' << mn_cpy + (d+1)*(i+1) << endl;
MinMax(mn_cpy+1 + (d+1)*i, mn_cpy + (d+1)*(i+1), &mn, &mx);
if (mn != -1) {
arr.push_back(mn);
arr.push_back(mx);
}
}
}
sort(arr.begin(), arr.end());
for (int i=0; i+1<n; ++i) gap = max(gap, arr[i+1]-arr[i]);
return gap;
}
Compilation message (stderr)
gap.cpp: In function 'll findGap(int, int)':
gap.cpp:26:25: warning: unused variable 'mx_cpy' [-Wunused-variable]
26 | ll mn_cpy = mn, mx_cpy = mx;
| ^~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |