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>
#include <algorithm>
#include <tuple>
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 {
long long findGap(int N) {
long long MIN, MAX;
MinMax(0, INF, &MIN, &MAX);
long long d = (MAX - MIN + 1 + N - 3) / (N - 2);
vector<pair<long long, long long>> rep;
for (long long l = MIN, r = MIN + d - 1; ; l += d, r += d) {
long long rep_l, rep_r;
MinMax(l, min(r, MAX), &rep_l, &rep_r);
if (rep_l == -1) continue;
rep.emplace_back(rep_l, rep_r);
if (r >= MAX)
break;
}
long long ans = 0;
for (int i = 0; i + 1 < (int)rep.size(); i++) {
long long l = rep[i].second, r = rep[i + 1].first;
ans = max(ans, r - l);
}
return 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... |