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>
#define CHECK cout << "ok" << endl
#define finish(x) return cout << x << endl, 0
typedef long long ll;
typedef long double ldb;
const int md = 1e9 + 7;
const ll inf = 1e18;
const int OO = 1;
const int OOO = 1;
using namespace std;
void MinMax(ll s, ll t, ll *mn, ll *mx);
ll findGap(int t, int n) {
ll lo, hi, a, b;
MinMax(0, inf, &lo, &hi);
if (t == 2) {
vector<ll> pos;
ll d = (hi - lo) / (n - 1);
pos.push_back(lo);
for (ll i = lo + 1; i < hi; i += d) {
MinMax(i, min(hi - 1, i + d - 1), &a, &b);
if (a != -1) {
pos.push_back(a);
pos.push_back(b);
}
}
pos.push_back(hi);
ll rtn = pos[1] - pos[0];
for (int i = 2; i < pos.size(); i++)
rtn = max(rtn, pos[i] - pos[i - 1]);
return rtn;
}
vector<ll> pos = { lo, hi };
int left = n - 2;
while (left > 0) {
MinMax(lo + 1, hi - 1, &lo, &hi);
pos.push_back(lo);
pos.push_back(hi);
left -= 2;
}
sort(pos.begin(), pos.end());
ll rtn = pos[1] - pos[0];
for (int i = 2; i < pos.size(); i++)
rtn = max(rtn, pos[i] - pos[i - 1]);
return rtn;
}
/*
int main() {
ll ans = findGap(0, 4);
cout << "my ans " << ans << '\n';
}
*/
Compilation message (stderr)
gap.cpp: In function 'll findGap(int, int)':
gap.cpp:30:21: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int i = 2; i < pos.size(); i++)
~~^~~~~~~~~~~~
gap.cpp:44:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int i = 2; i < pos.size(); i++)
~~^~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |