# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
108325 | 2019-04-28T14:08:07 Z | kuroni | Gap (APIO16_gap) | C++17 | 0 ms | 0 KB |
#include <iostream> #include <cstdio> #include <vector> #include <algorithm> using namespace std; long long findGap(int t, int n) { vector<long long> ve; if (t == 1) { long long le = 0, ri = 1E18; while (le <= ri) { long long mi, ma; MinMax(le, ri, mi, ma); if (mi > -1) { ve.push_back(mi); if (ma != mi) ve.push_back(ma); } le = mi + 1; ri = ma - 1; } } if (t == 2) { long long le, ri; MinMax(0, 1E18, le, ri); ve.push_back(le++); ve.push_back(ri--); long long ga = (ri - le + 1) / (n - 1), mo = (ri - le + 1) % (n - 1); for (int i = 1; i < n; i++) { long long mi, ma; MinMax(le, le + ga + (i <= mo) - 1, mi, ma); le += ga + (i <= mo); if (mi > -1) { ve.push_back(mi); if (ma != mi) ve.push_back(ma); } } } sort(ve.begin(), ve.end()); long long ans = 0; for (int i = 1; i < ve.size(); i++) ans = max(ans, ve[i] - ve[i - 1]); return ans; }