제출 #1127021

#제출 시각아이디문제언어결과실행 시간메모리
1127021duckindogSeesaw (JOI22_seesaw)C++20
34 / 100
2095 ms39440 KiB
#include <bits/stdc++.h> using namespace std; #define double long double const int N = 2'000 + 10; int n; int a[N]; long long pref[N]; inline long long sum(int l, int r) { return pref[r] - pref[l - 1]; } int way[N][N]; double f[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]; double answer = 1e9; for (int l = 1; l <= n; ++l) { for (int r = l; r <= n; ++r) { double mi = (double)sum(l, r) / (r - l + 1); { // clear for (int i = 1; i <= n; ++i) { for (int j = i; j <= n; ++j) f[i][j] = 1e9; } } f[1][n] = (double)sum(1, n) / n; for (int i = 1; i <= n; ++i) { for (int j = n; j > i; --j) { if ((double)sum(i, j) / (j - i + 1) < mi || f[i][j] == 1e9) continue; f[i][j] = max(f[i][j], (double)sum(i, j) / (j - i + 1)); f[i + 1][j] = min(f[i + 1][j], f[i][j]); f[i][j - 1] = min(f[i][j - 1], f[i][j]); } } for (int i = 1; i <= n; ++i) { if ((double)sum(i, i) / (i - i + 1) < mi || f[i][i] == 1e9) continue; f[i][i] = max(f[i][i], (double)sum(i, i) / (i - i + 1)); answer = min(answer, f[i][i] - mi); } } } cout << setprecision(9) << fixed << answer << "\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...