# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
713430 | Vu_CG_Coder | Gap (APIO16_gap) | C++14 | 0 ms | 0 KiB |
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);
int l = mn , long long 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();
else return sub2();
}