Submission #801916

#TimeUsernameProblemLanguageResultExecution timeMemory
801916fatemetmhrSeesaw (JOI22_seesaw)C++17
67 / 100
413 ms591000 KiB
// Be name khode // #include <bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; #define all(x) x.begin(), x.end() #define mp make_pair #define pb push_back #define fi first #define se second const int maxn5 = 2e3 + 5; int a[maxn5]; struct kasr{ __int128 up, dw; int l, r; kasr(){ } kasr(ll u, ll d){ up = u; dw = d; } } av[maxn5 * maxn5], keep[maxn5][maxn5]; bool operator <(kasr a, kasr b){ return a.up * b.dw < a.dw * b.up; } bool operator <=(kasr a, kasr b){ return a.up * b.dw <= a.dw * b.up; } ld operator -(kasr a, kasr b){ ld ax = a.up, ay = a.dw, bx = b.up, by = b.dw; return ax / ay - bx / by; } void out(kasr a){ cout << ld(a.up) << ' ' << ld(a.dw) << ' ' << ld(a.up) / ld(a.dw) << endl; } int main(){ ios_base::sync_with_stdio(false); cin.tie(0); int n; cin >> n; ll all = 0; int pt = 0; for(int i = 0; i < n; i++){ cin >> a[i]; all += a[i]; ll sum = 0; for(int j = i; j >= 0; j--){ sum += a[j]; av[pt].up = sum; av[pt].dw = (i - j + 1); av[pt].l = j; av[pt].r = i; keep[i][j] = av[pt]; pt++; } } sort(av, av + pt); kasr lim(all, n); kasr mnr = lim; ld ans = 1e18; for(int i = 0; i < pt && av[i] <= lim; i++){ ans = min(ans, mnr - av[i]); //cout << i << ' ' << av[i].l << ' ' << av[i].r << ' ' << ans << endl; //out(mnr); //out(av[i]); int v = av[i].r; if(v + 1 < n && mnr < keep[v + 1][av[i].l + 1]) mnr = keep[v + 1][av[i].l + 1]; } cout << setprecision(15) << ans << endl; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...