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 "gap.h"
#include<bits/stdc++.h>
using namespace std;
#define f first
#define s second
typedef long long ll;
ll ans = 0;
int n;
bool cmp(pair<ll, ll> a, pair<ll, ll> b){return b.f-a.f < b.s - a.s;}
void solve(ll l, ll r, ll ele){
if(r-l <= ans)return;
ll dist;
if(ele >= 5)dist = min((r-l+ele*2)/ele*2, r-l-1);
else dist = (r-l+ele)/ele;
vector<pair<ll, ll>> A;
for(ll i = l; i <= r; i+=dist){
pair<ll, ll> tmp;
MinMax(i, min(i+dist-1, r), &tmp.f, &tmp.s);
if(tmp.s > 0){
ele -= 1+(tmp.f != tmp.s);
A.push_back(tmp);
}
}
for(int i = 1; i < A.size(); i++){
if(A[i-1].f != -1 && A[i].f != -1)ans = max(ans, A[i].f - A[i-1].s);
}
sort(A.begin(), A.end(), cmp);
reverse(A.begin(), A.end());
for(auto v: A)solve(v.f, v.s, ele+1+(v.f != v.s));
}
long long findGap(int T, int N)
{
n = N;
solve(0, 1e18, N);
return ans;
}
Compilation message (stderr)
gap.cpp: In function 'void solve(ll, ll, ll)':
gap.cpp:30:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
30 | for(int i = 1; i < A.size(); i++){
| ~~^~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |