Submission #371447

#TimeUsernameProblemLanguageResultExecution timeMemory
371447SortingGap (APIO16_gap)C++17
100 / 100
70 ms1288 KiB
#include "gap.h" #include <bits/stdc++.h> using namespace std; typedef long long ll; using namespace std; mt19937 mt(2); void check_max(ll &a, ll b){ a = (b > a) ? b : a; } const ll INF = 1e18; int t, n; ll solve_1(){ ll l, r, ans = 0; MinMax(0, INF, &l, &r); ll l2, r2; n -= 2; while(n > 0){ MinMax(l + 1, r - 1, &l2, &r2); ans = max(ans, max(l2 - l, r - r2)); l = l2, r = r2; n -= 2; } ans = max(ans, r - l); return ans; } ll findGap(int _t, int _n){ t = _t, n = _n; if(t == 1) return solve_1(); if(n <= 1) return 0; ll l, r; MinMax(0, INF, &l, &r); ll bound = ((r - l) / (n - 1)) + !!((r - l) % (n - 1)), ans = bound; ll prev = l; for(ll i = l; i < r; i += bound + 1){ ll l2, r2; MinMax(i, i + bound, &l2, &r2); if(l2 != -1){ check_max(ans, l2 - prev); prev = r2; } } return ans; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...