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 <stdio.h>
#include <stdlib.h>
#include <vector>
#include <bits/stdc++.h>
#include "gap.h"
#define ll long long
using namespace std;
long long sub1(int n)
{
long long l = 0 , r = 1e18;
vector <long long> kq;
for (int i = 1 ; i <= (n + 1)/2 ; i++)
{
ll s , t;
MinMax(l,r,&s,&t);
kq.push_back(s);
kq.push_back(t);
l = (s) + 1;
r = (t) - 1;
}
sort(kq.begin(),kq.end());
long long res = 0;
for (int i = 1 ; i < kq.size() ; i++)
res = max(res,kq[i] - kq[i - 1]);
return res;
}
long long sub2(int n)
{
long long mn , mx , a = 0 , b = 1e18;
MinMax(a,b,&mn,&mx);
long long res = 0;
long long step = (mx - mn + 1 + n)/(n - 1);
long long l = mn , i = step;
for (i = step ; i <= mx ; i += step)
{
long long x , y;
MinMax(i + 1,min(i+step,mx),&x,&y);
if (x != -1)
{
res = max(res,x - l);
l = y;
}
}
return res;
}
long long findGap(int t , int n)
{
if (t == 1) return sub1(n);
else return sub2(n);
}
Compilation message (stderr)
gap.cpp: In function 'long long int sub1(int)':
gap.cpp:28:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
28 | for (int i = 1 ; i < kq.size() ; i++)
| ~~^~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |