제출 #1127058

#제출 시각아이디문제언어결과실행 시간메모리
1127058duckindogSeesaw (JOI22_seesaw)C++20
67 / 100
597 ms41068 KiB
#include <bits/stdc++.h> using namespace std; #define double long double const int N = 2'000 + 10; const double MAX = 1e9; int n; int a[N]; long long pref[N]; inline long long sum(int l, int r) { return pref[r] - pref[l - 1]; } inline double cal(int l, int r) { return (double)sum(l, r) / (r - l + 1); } int way[N][N]; pair<int, int> par[N][N]; bool mk[N][N]; int32_t main() { cin.tie(0)->sync_with_stdio(0); cin >> n; for (int i = 1; i <= n; ++i) cin >> a[i]; for (int i = 1; i <= n; ++i) pref[i] = pref[i - 1] + a[i]; using TP = tuple<double, int, int>; priority_queue<TP, vector<TP>, greater<>> q; multiset<double> s; double answer = MAX; auto go = [&](int x, int y) { if (!x && !y) return; while (x != y) { if (!mk[x][y]) s.insert(cal(x, y)), q.emplace(cal(x, y), x, y), mk[x][y] = true; int nX = (!way[x][y] ? x : x + 1), nY = (!way[x][y] ? y - 1 : y); par[nX][nY] = {x, y}; tie(x, y) = {nX, nY}; if (mk[x][y]) break; } if (!mk[x][y]) s.insert(cal(x, y)), q.emplace(cal(x, y), x, y), mk[x][y] = true; answer = min(answer, *s.rbegin() - *s.begin()); }; go(1, n); while (q.size()) { auto [d, i, j] = q.top(); q.pop(); if (i != 1 || j != n) s.extract(d); auto [x, y] = par[i][j]; if (way[x][y]) continue; way[x][y] = 1; go(x, y); } cout << setprecision(9) << fixed << answer << "\n"; cerr << 1.0 * clock() / CLOCKS_PER_SEC << "\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...