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>
#define all(x) (x).begin(),(x).end()
using namespace std;
using ll = long long;
using pii = pair<ll, ll>;
ll findGap(int t, int n) {
// cerr << t << ' ' << n << '\n';
ll l = 0, r = 1e18;
if(t == 1) {
set<ll> elem;
l--;
r++;
while(l <= r && n > 0) {
if(l + 1 > r - 1)
break;
MinMax(l + 1, r - 1, &l, &r);
if(l == -1)
break;
elem.insert(l);
elem.insert(r);
n -= 1 + (l != r);
// cerr << n << ' ' ;
}
auto it = elem.begin();
it++;
ll mx = - 1;
for(auto i = next(it); i != elem.end(); i++)
mx = max(mx, *it - *prev(it));
return mx;
}
MinMax(l, r, &l, &r);
ll mx = r;
vector<pii> v;
ll minl = (r - l + n - 2) / (n - 1);
v.emplace_back(l, l);
// cerr << l << ' ' << r << ' ' << minl << '\n';
for(ll i = l; i < mx; i += minl) {
// cerr << i << ' ' << i + minl << ' ' << mx << '\n';
MinMax(i, min(mx, i + minl) - 1, &l, &r);
if(l == -1)
continue;
v.emplace_back(l, r);
}
v.emplace_back(mx, mx);
mx = -1;
for(int i = 1; i < v.size(); i++)
mx = max(v[i].first - v[i - 1].second, mx);
return mx;
}
Compilation message (stderr)
gap.cpp: In function 'll findGap(int, int)':
gap.cpp:47:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
47 | for(int i = 1; i < v.size(); i++)
| ~~^~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |