This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
#include <bits/stdc++.h>
#include "gap.h"
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int, int> pi;
#define debug(x) cerr << #x << ": " << x << endl;
#define debug2(x, y) debug(x) debug(y);
#define repn(i, a, b) for(int i = (int)(a); i < (int)(b); i++)
#define rep(i, a) for(int i = 0; i < (int)(a); i++)
#define all(v) v.begin(), v.end()
#define mp make_pair
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define sq(x) ((x) * (x))
template<class T> T gcd(T a, T b){ return ((b == 0) ? a : gcd(b, a % b)); }
ll findGap(int t, int n){
if(t == 1){
ll l = 0, r = 1e18;
ll mn = 0, mx = 0;
MinMax(l, r, &mn, &mx);
l = mn, r = mx;
int cnt = 0;
if(l != r) cnt = 2;
else cnt = 1;
ll ans = 0;
int f = 1;
while(cnt < n){
MinMax(l + 1, r - 1, &mn, &mx);
ans = max({mn - l, ans, r - mx});
l = mn, r = mx;
if(l == r) cnt++;
else cnt += 2;
}
ans = max(ans, r - l);
return ans;
}
else{
ll low = -1; //our current best
ll ans = 0;
ll prev = 0;
rep(i, n){
ll l = low + 1, r = 1e18;
while(l < r){
ll mid = (l + r) / 2;
ll mn = 0, mx = 0;
MinMax(low + 1, mid, &mn, &mx);
if(mn == -1) l = mid + 1;
else r = mid;
}
if(i) ans = max(ans, l - prev);
prev = l;
low = l;
}
return ans;
}
}
/*
Things to look out for:
- Integer overflows
- Array bounds
- Special cases
Be careful!
*/
Compilation message (stderr)
gap.cpp: In function 'll findGap(int, int)':
gap.cpp:35:7: warning: unused variable 'f' [-Wunused-variable]
int f = 1;
^
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |