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 ll = long long;
using namespace std;
long long findGap(int T, int N){
if (T == 1 or N == 2){
ll pmini = 0, pmaxi = 1e18+2;
vector<ll> ans;
for (int i=0; i<(N+1)/2; ++i){
long long a,b;
MinMax(pmini,pmaxi,&a,&b);
ans.emplace_back(a);
ans.emplace_back(b);
pmini = a+1;
pmaxi = b-1;
}
sort(ans.begin(),ans.end());
ll res = 0;
for (int i=1; i<ans.size(); ++i){
res = max(res,ans[i]-ans[i-1]);
}
return res;
}
else{
ll mini,maxi, MAX_VAL = 1e18;
MinMax(0ll,MAX_VAL,&mini,&maxi);
ll block_siz = (maxi-mini-1)/(N-1)-1, prev = mini, ans = 0;
for (int i=mini+1; i<=maxi-1; i += block_siz){
ll a,b;
MinMax(i,i+block_siz,&a,&b);
if (a != -1) ans = max(ans,a-prev);
if (b != -1) prev = b;
++i;
}
return ans;
}
}
Compilation message (stderr)
gap.cpp: In function 'long long int findGap(int, int)':
gap.cpp:20:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
20 | for (int i=1; i<ans.size(); ++i){
| ~^~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |