Submission #946581

#TimeUsernameProblemLanguageResultExecution timeMemory
946581n3rm1nGap (APIO16_gap)C++17
30 / 100
182 ms3452 KiB
#include<bits/stdc++.h> #include "gap.h" using namespace std; const int MAXN = 2e5 + 10; long long a[MAXN]; long long findGap(int T, int N) { if(T == 1) { long long s = 0, t = (long long)(1e18); long long mn, mx; long long n = N; long long filled0 = 0, filled1 = n+1; while(filled0 + 1 <= filled1 - 1) { MinMax(s, t, &mn, &mx); if(mn == mx) { filled0 ++; a[filled0] = mn; n --; break; } filled0 ++; filled1 --; n-= 2; a[filled0] = mn; a[filled1] = mx; s = mn + 1; t = mx - 1; } long long ans = -1; //cout << "n is " << n << endl; //cout << a[1] << " "; for (int i = 2; i <= N; ++ i) { //cout << a[i] << " "; ans = max(ans, (long long) (a[i] - a[i-1])); } //cout << endl; //cout << ans << endl; return ans; } long long s = 0, t = 1e18, mn, mx; MinMax(s, t, &mn, &mx); long long curr = mn, last = mx; long long ans = 1; while(curr < last) { // cout << curr << endl; // cout << "* " << ans << endl; s = curr + 1; t = curr + ans; if(s < t) { MinMax(s, t, &mn, &mx); if(mn != -1 && mx != -1) { curr = mn; //cout << "move to " << curr << endl; continue; } } long long lf = ans, rth = last - curr, mid, newans = -1; long long found = 0; /// koga se e promenilo za pyrvi pyt while(lf <= rth) { mid = (lf + rth) / 2; s = curr + 1; t = curr + mid + 1; MinMax(s, t, &mn, &mx); if(mn == -1 && mx == -1) { lf = mid + 1; } else { rth = mid - 1; found = mn; newans = mid; } } // cout << "found is " << found << endl; if(newans != -1)ans = max(ans, found - curr); else break; curr = found; } return ans; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...