제출 #1127169

#제출 시각아이디문제언어결과실행 시간메모리
1127169vladiliusSeesaw (JOI22_seesaw)C++20
34 / 100
2097 ms40060 KiB
#include <bits/stdc++.h> using namespace std; using ll = long long; using pii = pair<int, int>; using pdi = pair<double, int>; #define pb push_back #define ff first #define ss second struct ST{ vector<int> a; int n; ST(int ns){ n = ns; a.resize(n + 1); } void upd(int p, int x){ a[p] += x; } int get(){ int out = 0; for (int i: a){ out = max(out, i); } return out; } }; int main(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n; cin>>n; vector<int> a(n + 1); vector<ll> p(n + 1); for (int i = 1; i <= n; i++){ cin>>a[i]; p[i] = p[i - 1] + a[i]; } if (n > 2e3) return 0; vector<vector<double>> X(n + 1, vector<double>(n + 1)); for (int i = 1; i <= n; i++){ for (int j = i; j <= n; j++){ X[i][j] = 1.0 * (p[j] - p[i - 1]) / (j - i + 1); } } priority_queue<pdi, vector<pdi>, greater<pdi>> pq; for (int i = 1; i <= n; i++) pq.push({X[1][n - i + 1], i}); vector<int> t(n + 1, 1); vector<pii> all = {{0, 0}}; int j = 1; ST T(n); double out = 1e9 + 1; while (!pq.empty()){ auto [V, i] = pq.top(); pq.pop(); int r = t[i] + n - i; if (t[i] == 1){ for (int j = 1; j <= r; j++){ T.upd(j, 1); } } else { T.upd(r, 1); } if (r < n){ pq.push({X[t[i] + 1][r + 1], i}); } all.pb({t[i]++, r}); while (T.get() == n && j < all.size()){ auto [l, r] = all[j]; if (r == n) break; int ii = n - (r - l); if (l == (t[ii] - 1)){ for (int f = t[ii] - 1; f <= t[ii] - 1 + n - ii; f++){ T.upd(f, -1); } } else { T.upd(l, -1); } if (T.get() != n){ if (l == (t[ii] - 1)){ for (int f = t[ii] - 1; f <= t[ii] - 1 + n - ii; f++){ T.upd(f, 1); } } else { T.upd(l, 1); } break; } j++; } if (T.get() == n){ auto [l, r] = all[j]; out = min(out, V - X[l][r]); } } cout<<fixed<<setprecision(12)<<out<<"\n"; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...