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 namespace std;
typedef long long ll;
typedef pair<int, int> pii;
#define fi first
#define se second
#define mp make_pair
long long findGap(int T, int N){
if(T == 1){
ll low = -1, high = (ll)1e18 + 1;
vector<ll> C(N);
int L = 0, R = N - 1;
for(int i = 0 ; i < (N + 1) / 2; i ++ ){
MinMax(low + 1, high - 1, &low, &high);
C[L] = low;
C[R] = high;
L ++ ;
R -- ;
}
ll res = 0;
for(int i = 1; i < N; i ++ ){
res = max(res, C[i] - C[i - 1]);
}
return res;
}
ll low=0, high=0;
ll lim = (ll)1e18;
MinMax(0ll, lim, &low, &high);
ll S = (high - low + (N - 1) - 1) / (N - 1); // the gap is atleast S
ll gl = low + 1;
ll gr;
vector<ll> in;
in.push_back(low);
if(N >= 3){
ll ca, cb;
while(gl <= high){
gr = min(high - 1, gl + S);
MinMax(gl, gr, &ca, &cb);
gl += S + 1;
if(ca == -1) continue;
in.push_back(ca);
in.push_back(cb);
}
}
in.push_back(high);
ll res = 0;
for(int i = 1; i < in.size(); i ++ ){
res = max(res, in[i] - in[i - 1]);
}
return res;
}
Compilation message (stderr)
gap.cpp: In function 'long long int findGap(int, int)':
gap.cpp:52:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
52 | for(int i = 1; i < in.size(); i ++ ){
| ~~^~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |