Submission #1101331

#TimeUsernameProblemLanguageResultExecution timeMemory
1101331huyngoGap (APIO16_gap)C++17
30 / 100
53 ms4172 KiB
#include "gap.h" #include<bits/stdc++.h> using namespace std; #define ll long long long long findGap(int T, int N) { if (T == 1) { vector<ll> a; auto calc = [&](auto self, ll l, ll r) -> void { if (l > r || (int)a.size() == N) return; ll x, y; MinMax(l, r, &x, &y); if (x != -1) a.push_back(x); if (y != x) a.push_back(y); self(self, x + 1, y - 1); }; calc(calc, 0, 1e18); sort(a.begin(), a.end()); ll res = a[1] - a[0]; for (int i = 2; i < N; ++i) res = max(res, a[i] - a[i - 1]); return res; } ll mn, mx; MinMax(1, 1e18, &mn, &mx); ll step = (mx - mn) / (N - 1); ll ans = step, x, y, l = mn, i; for (i = mn + 1; i + step <= mx; i += step) { MinMax(i, i + step, &x, &y); if (x != -1) { ans = max(ans, x - l); l = y; } } return ans; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...