Submission #540522

#TimeUsernameProblemLanguageResultExecution timeMemory
540522dutinmeowGap (APIO16_gap)C++17
100 / 100
59 ms2260 KiB
#include <bits/stdc++.h> using namespace std; #include "gap.h" const long long MAX_A = 1e18; long long findGap(int T, int N) { if (T == 1) { long long l = 1, r = MAX_A; vector<long long> A; for (int i = 0; i < (N + 1) / 2; i++) { long long nl, nr; MinMax(l, r, &nl, &nr); A.push_back(nl); A.push_back(nr); l = nl + 1, r = nr - 1; } sort(A.begin(), A.begin() + N); long long ans = 0; for (int i = 1; i < N; i++) ans = max(ans, A[i] - A[i - 1]); return ans; } else { long long l, r; MinMax(1, MAX_A, &l, &r); long long step = (r - l + N - 2) / (N - 1); long long lb, ans = step; for (lb = l; lb + step < r; lb += step + 1) { long long nl, nr; MinMax(lb, lb + step, &nl, &nr); if (nl != -1 && nr != -1) { ans = max(ans, nl - l); l = nr; } } long long nl, nr; MinMax(lb, r, &nl, &nr); if (nl != -1 && nr != -1) ans = max(ans, nl - l); return ans; } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...