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 <algorithm>
#include <cmath>
using namespace std;
long long findGap(int T, int N)
{
long long res = 0;
if(T == 1)
{
long long s, t;
long long mn;
long long mx;
s = 0;
t = 1000'000'000'000'000'000LL;
if(N % 2 == 0)
{
MinMax(s, t, &mn, &mx);
s = mn + 1;
t = mx - 1;
for(int i = 2; i <= N/2; i++)
{
MinMax(s, t, &mn, &mx);
res = max(res, mn - (s-1));
res = max(res, (t+1) - mx);
s = mn + 1;
t = mx - 1;
}
res = max(res, mx - mn);
}
else
{
MinMax(s, t, &mn, &mx);
s = mn + 1;
t = mx - 1;
for(int i = 2; i <= (N+1)/2; i++)
{
MinMax(s, t, &mn, &mx);
res = max(res, mn - (s-1));
res = max(res, (t+1) - mx);
s = mn + 1;
t = mx - 1;
}
}
}
else if(T == 2)
{
long long s, t;
long long mn, mx;
s = 0;
t = 1'000'000'000'000'000'000LL;
MinMax(s, t, &mn, &mx); //M += N+1
long long a1 = mn, aN = mx;
long long gap = (aN-a1)/(N-1) + ((aN-a1) % (N-1) != 0);
vector<long long> L, R;
L.push_back(a1);
R.push_back(a1);
for(long long x = a1+1; x < aN; x += gap)
{
MinMax(x, std::min(x+gap-1, aN-1), &mn, &mx);
if (mn != -1)
{
L.push_back(mn);
R.push_back(mx);
}
}
L.push_back(aN);
R.push_back(aN);
for(int i = 0; i < L.size()-1; i++)
{
res = max(res, L[i+1] - R[i]);
}
}
return res;
}
Compilation message (stderr)
gap.cpp: In function 'long long int findGap(int, int)':
gap.cpp:79:18: 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 = 0; i < L.size()-1; i++)
| ~~^~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |