Submission #631541

#TimeUsernameProblemLanguageResultExecution timeMemory
631541TranGiaHuy1508Gap (APIO16_gap)C++17
100 / 100
61 ms2648 KiB
#include <bits/stdc++.h> using namespace std; #include "gap.h" using ll = long long; ll findGap(int T, int N){ if (T == 1){ ll mn, mx; vector<ll> L, R; ll lb = -1, rb = (ll)1e18 + 1; while (N > 0 && lb + 1 <= rb - 1){ MinMax(lb + 1, rb - 1, &mn, &mx); if (mn < 0) break; L.push_back(mn); R.push_back(mx); N--; if (mn != mx) N--; lb = mn; rb = mx; } ll res = 0; for (int i = 1; i < (int)L.size(); i++){ res = max(res, abs(L[i] - L[i-1])); } for (int i = 1; i < (int)R.size(); i++){ res = max(res, abs(R[i] - R[i-1])); } res = max(res, abs(R.back() - L.back())); return res; } else{ ll mn, mx; MinMax(0, (ll)1e18, &mn, &mx); ll d = mx - mn; ll st = mn + 1; vector<pair<ll, ll>> v(N); for (int i = 0; i < N; i++){ ll dist = d/N + (i < d%N); v[i] = {st, st + dist - 1}; st += dist; } ll res = 0, lst = mn; for (int i = 0; i < N; i++){ if (v[i].first <= v[i].second){ ll a, b; MinMax(v[i].first, v[i].second, &a, &b); if (a < 0) continue; res = max(res, a - lst); res = max(res, b - a); lst = b; } } return res; } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...