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;
const int MAXN = 1e5 + 2;
ll K = 6, n;
vector<ll> ans;
ll f(ll L, ll R){
return max(1LL, (R - L + K - 1) / K);
}
void solve(ll L, ll R){
if(L > R || ans.size() == n) return ;
ll d = f(L, R);
for(ll i = L; i <= R; i += d){
if(ans.size() == n) return ;
ll val_l = i, val_r = min(R, i + d - 1);
assert(val_l <= val_r);
MinMax(val_l, val_r, &val_l, &val_r);
if(val_l != -1){
ans.push_back(val_l);
if(val_r != val_l){
ans.push_back(val_r);
solve(val_l + 1, val_r - 1);
}
}
}
}
ll findGap(int t, int _n){
n = _n;
if(t == 1){
int L = 0, R = n - 1;
ll val_l = 1, val_r = 1e18;
while(L <= R){
MinMax(val_l, val_r, &val_l, &val_r);
ans.push_back(val_l);
if(val_r != val_l) ans.push_back(val_r);
++L; --R;
++val_l; --val_r;
}
} else {
solve(1, 1e18);
}
ll ret = 0;
sort(ans.begin(), ans.end());
for(int i = 0; i < (int)ans.size() - 1; ++i) ret = max(ret, ans[i + 1] - ans[i]);
return ret;
}
Compilation message (stderr)
gap.cpp: In function 'void solve(ll, ll)':
gap.cpp:14:25: warning: comparison of integer expressions of different signedness: 'std::vector<long long int>::size_type' {aka 'long unsigned int'} and 'll' {aka 'long long int'} [-Wsign-compare]
14 | if(L > R || ans.size() == n) return ;
| ~~~~~~~~~~~^~~~
gap.cpp:17:17: warning: comparison of integer expressions of different signedness: 'std::vector<long long int>::size_type' {aka 'long unsigned int'} and 'll' {aka 'long long int'} [-Wsign-compare]
17 | if(ans.size() == n) return ;
| ~~~~~~~~~~~^~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |