Submission #677638

# Submission time Handle Problem Language Result Execution time Memory
677638 2023-01-04T05:20:37 Z jhwest2 Seesaw (JOI22_seesaw) C++17
100 / 100
98 ms 11648 KB
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef long double ld;
const int N = 202020;

int n; ll a[N], psum[N];
int main() {
    cin.tie(0); ios_base::sync_with_stdio(0);
    cin >> n;
    for (int i = 1; i <= n; i++) {
        cin >> a[i];
        psum[i] = psum[i - 1] + a[i];
    }
    vector<pair<ld, ld>> v(n);
    for (int i = 1; i <= n; i++) {
        int L = 0, R = i - 1;
        while (L < R) {
            int M = (L + R + 1) / 2;

            if ((ld)(psum[M + n + 1 - i] - psum[M]) / (n + 1 - i) <= (ld)psum[n] / n)
                L = M;
            else 
                R = M - 1;
        }
        v[i - 1].first = (ld)(psum[L + n + 1 - i] - psum[L]) / (n + 1 - i);

        L = 0; R = i - 1;
        while (L < R) {
            int M = (L + R) / 2;

            if ((ld)(psum[M + n + 1 - i] - psum[M]) / (n + 1 - i) >= (ld)psum[n] / n)
                R = M;
            else
                L = M + 1;
        }
        v[i - 1].second = (ld)(psum[L + n + 1 - i] - psum[L]) / (n + 1 - i);
    }
    sort(v.begin(), v.end());
    ld maxv = (ld)psum[n] / n;
    ld ans = 1e12;
    for (auto [x, y] : v) {
        ans = min(ans, maxv - x);
        maxv = max(maxv, y);
    }
    cout.precision(15);
    cout << fixed << ans;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 2 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 2 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 2 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 2 ms 340 KB Output is correct
12 Correct 89 ms 11640 KB Output is correct
13 Correct 98 ms 11596 KB Output is correct
14 Correct 83 ms 11636 KB Output is correct
15 Correct 85 ms 11648 KB Output is correct
16 Correct 85 ms 11648 KB Output is correct