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;
long long n;
long long bck = 1000;
long long pmax = 0;
long long solve1()
{
int l = 1;
int r = n;
long long st = 0, dr = 1e18;
vector<long long> a,b;
while(l<=r)
{
long long x,y;
MinMax(st,dr,&x,&y);
a.push_back(x);
b.push_back(y);
++l;
--r;
st = x + 1;
dr = y - 1;
}
vector<long long> v;
for(auto it : a)
{
v.push_back(it);
}
reverse(b.begin(),b.end());
for(auto it : b)
{
v.push_back(it);
}
long long Max = 0;
for(int i=1;i<v.size();i++)
{
Max = max(Max,v[i] - v[i-1]);
}
return Max;
}
long long solve2(long long st, long long dr)
{
MinMax(st,dr,&st,&dr);
long long pmax = (dr - st + n - 2) / (n - 1);
long long last = -1;
long long rez = -1;
if(n==2)
{
return dr - st;
}
while(st<=dr)
{
long long l = st;
long long r = min(dr,l + pmax);
MinMax(l,r,&l,&r);
if(l!=-1 && last!=-1)
{
rez = max(rez,l-last);
}
if(l!=-1)
{
last = r;
}
st += pmax + 1;
}
return rez;
}
long long findGap(int t, int N)
{
n = N;
if(t==1)
{
return solve1();
}
return solve2(1,1e18);
}
Compilation message (stderr)
gap.cpp: In function 'long long int solve1()':
gap.cpp:39:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
39 | for(int i=1;i<v.size();i++)
| ~^~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |