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;
ll subtask1(int N);
ll subtask2(ll s = 0, ll e = 1e18)
{
if(s >= e) return 0;
ll mid = (s + e) / 2;
ll mx1, mx2, mn1, mn2;
MinMax(s, mid, &mn1, &mx1);
MinMax(mid + 1, e, &mn2, &mx2);
if(mn2 == -1) return subtask2(mn1, mx1);
if(mn1 == -1) return subtask2(mn2, mx2);
ll ans = mn2 - mx1;
if(mx1 - mn1 < mx2 - mx2)
swap(mx1, mx2), swap(mn1, mn2);
if(ans < mx1 - mn1)
ans = max(ans, subtask2(mn1, mx1));
if(ans < mx2 - mn2)
ans = max(ans, subtask2(mn2, mx2));
return ans;
}
ll findGap(int T, int N)
{
if(T == 1)
return subtask1(N);
return subtask2();
}
ll subtask1(int N)
{
int i = 0, j = N - 1;
ll s = 0, e = 1e18;
ll *mn = new ll, *mx = new ll;
vector<ll> v(N);
while(i <= j && s <= e)
{
MinMax(s, e, mn, mx);
v[i] = *mn;
v[j] = *mx;
i++, j--;
s = *mn + 1;
e = *mx - 1;
}
ll ans = 0;
for(int i = 1; i < v.size(); i++)
ans = max(ans, v[i] - v[i - 1]);
return ans;
}
Compilation message (stderr)
gap.cpp: In function 'll subtask1(int)':
gap.cpp:79:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
79 | for(int i = 1; i < v.size(); i++)
| ~~^~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |