Submission #802971

# Submission time Handle Problem Language Result Execution time Memory
802971 2023-08-02T16:54:29 Z myst6 Seesaw (JOI22_seesaw) C++14
34 / 100
2000 ms 156896 KB
#pragma GCC optimize("O2")

#include <bits/stdc++.h>

using namespace std;
using ll = long long;

int main() {
    // freopen("seesaw.txt","r",stdin);

    cin.tie(0)->sync_with_stdio(0);
    int N;
    cin >> N;
    vector<ll> A(N);
    for (int i=0; i<N; i++) cin >> A[i];
    double bary[N][N];
    set<double> baries;
    memset(bary, 0, sizeof bary);
    for (int i=0; i<N; i++) {
        ll sum = 0;
        for (int j=i; j<N; j++) {
            sum += A[j];
            bary[i][j] = (double)sum / (double)(j - i + 1);
            baries.insert(bary[i][j]);
        }
    }
    double ans = 1e9;
    double dp[N][N];
    cout << setprecision(100);
    double upper_bound = bary[0][N-1];
    while (upper_bound > 0) {
        double next_upper_bound = -1;
        memset(dp, 0, sizeof dp);
        for (int len=0; len<N; len++) {
            for (int i=0; i<N-len; i++) {
                if (len > 0) {
                    if (bary[i+1][i+len] <= upper_bound) {
                        dp[i][i+len] = min(bary[i][i+len], max(
                            dp[i+1][i+len],
                            dp[i][i+len-1]
                        ));
                    } else {
                        if (bary[i+1][i+len] < next_upper_bound || next_upper_bound == -1) {
                            next_upper_bound = bary[i+1][i+len];
                        }
                        // if (abs(bary[i+1][i+len] - upper_bound) < 1)
                        //     cout << bary[i+1][i+len] << " >= " << upper_bound << "\n";
                        dp[i][i+len] = min(bary[i][i+len], dp[i][i+len-1]);
                    }
                } else {
                    dp[i][i+len] = bary[i][i+len];
                }
            }
        }
        // cout << dp[0][N-1] << "\n";
        ans = min(ans, upper_bound - dp[0][N-1]);
        upper_bound = next_upper_bound;
        // cout << upper_bound << ":\n";
        // for (int i=0; i<N; i++) {
        //     for (int j=0; j<N; j++) {
        //         cout << dp[i][j] << " ";
        //     }
        //     cout << "\n";
        // }
        // cout << "\n";
    }
    cout << ans << "\n";
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 42 ms 684 KB Output is correct
5 Correct 44 ms 596 KB Output is correct
6 Correct 41 ms 688 KB Output is correct
7 Correct 45 ms 692 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 42 ms 684 KB Output is correct
5 Correct 44 ms 596 KB Output is correct
6 Correct 41 ms 688 KB Output is correct
7 Correct 45 ms 692 KB Output is correct
8 Execution timed out 2070 ms 156896 KB Time limit exceeded
9 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 42 ms 684 KB Output is correct
5 Correct 44 ms 596 KB Output is correct
6 Correct 41 ms 688 KB Output is correct
7 Correct 45 ms 692 KB Output is correct
8 Execution timed out 2070 ms 156896 KB Time limit exceeded
9 Halted 0 ms 0 KB -