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 <vector>
#include <iostream>
#include <random>
using namespace std;
const long long INF = 1e18;
mt19937_64 rnd(23478612);
inline long long random(long long MIN, long long MAX) {
return rnd() % (MAX - MIN + 1) + MIN;
}
long long calc_cost(const vector<long long> &seq) {
long long res = 0;
for (int i = 0; i + 1 < (int)seq.size(); i++)
res = max(res, seq[i + 1] - seq[i]);
return res;
}
namespace SUB1 {
long long findGap(int N) {
vector<long long> seq(N);
long long L = 0, R = INF;
for (int i = 0, j = N - 1; i <= j; i++, j--) {
MinMax(L, R, &seq[i], &seq[j]);
L = seq[i] + 1, R = seq[j] - 1;
}
return calc_cost(seq);
}
}
namespace SUB2 {
vector<long long> ans;
void solve(long long MIN, long long MAX) {
if (MIN > MAX)
return;
if (MIN == MAX) {
ans.push_back(MIN);
return;
}
long long L, R;
MinMax(MIN, MAX, &L, &R);
if (L == -1 and R == -1)
return;
if (L == R) {
ans.push_back(L);
return;
}
if (L == MIN and R == MAX) {
ans.push_back(L);
ans.push_back(R);
return;
}
long long M = random(L + 1, R - 1);
//long long M = (L + R) / 2;
ans.push_back(L);
solve(L + 1, M);
solve(M + 1, R - 1);
ans.push_back(R);
}
long long findGap(int N) {
solve(0, INF);
return calc_cost(ans);
}
}
long long findGap(int T, int N) {
return (T == 1) ? SUB1::findGap(N) : SUB2::findGap(N);
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |