Submission #548055

#TimeUsernameProblemLanguageResultExecution timeMemory
548055SamNguyenGap (APIO16_gap)C++14
16.22 / 100
68 ms2240 KiB
#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; 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 (R - L == 1) { 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); /* for (long long e : ans) cerr << e << " "; cerr << endl; */ return calc_cost(ans); } } long long findGap(int T, int N) { //return (T == 1) ? SUB1::findGap(N) : SUB2::findGap(N); return SUB2::findGap(N); }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...