Submission #677955

# Submission time Handle Problem Language Result Execution time Memory
677955 2023-01-04T17:57:58 Z qwerasdfzxcl Seesaw (JOI22_seesaw) C++17
67 / 100
1100 ms 133444 KB
#include <bits/stdc++.h>

typedef long long ll;
using namespace std;
struct Frac{
    ll a, b;
    Frac(){}
    Frac(ll _a, ll _b): a(_a), b(_b) {}

    long double ch()const{return (long double) a / b;}

    bool operator < (const Frac &F) const{
        return (__int128)a * F.b < (__int128)b * F.a;
    }
}val[2020][2020];

int n, a[200200], idx[200200];
set<pair<Frac, int>> st;

int main(){
    scanf("%d", &n);
    for (int i=1;i<=n;i++) scanf("%d", a+i);

    for (int i=1;i<=n;i++){
        val[i][i] = Frac(a[i], 1);
        for (int j=i+1;j<=n;j++){
            val[i][j].a = val[i][j-1].a + a[j];
            val[i][j].b = j-i+1;
        }
    }

    for (int d=0;d<=n-1;d++){
        for (int i=n-d;i;i--){
            int j = i+d;
            if (i==1 || val[i][j] < val[1][n]){
                st.emplace(val[i][j], d);
                idx[d] = i;
                break;
            }
        }
    }

    long double ans = 1e18;

    while(!st.empty()){
        ans = min(ans, st.rbegin()->first.ch() - st.begin()->first.ch());

        auto [x, d] = *st.begin();
        st.erase(st.begin());
        //printf("%Lf %d\n", x.ch(), d);
        if (idx[d]+1+d > n) break;

        st.emplace(val[idx[d]+1][idx[d]+1+d], d);


    }

    printf("%.15Lf\n", ans);
    return 0;
}

Compilation message

seesaw.cpp: In function 'int main()':
seesaw.cpp:21:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   21 |     scanf("%d", &n);
      |     ~~~~~^~~~~~~~~~
seesaw.cpp:22:33: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   22 |     for (int i=1;i<=n;i++) scanf("%d", a+i);
      |                            ~~~~~^~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 724 KB Output is correct
5 Correct 1 ms 724 KB Output is correct
6 Correct 1 ms 724 KB Output is correct
7 Correct 1 ms 724 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 724 KB Output is correct
5 Correct 1 ms 724 KB Output is correct
6 Correct 1 ms 724 KB Output is correct
7 Correct 1 ms 724 KB Output is correct
8 Correct 22 ms 39260 KB Output is correct
9 Correct 23 ms 39316 KB Output is correct
10 Correct 23 ms 39248 KB Output is correct
11 Correct 25 ms 39336 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 724 KB Output is correct
5 Correct 1 ms 724 KB Output is correct
6 Correct 1 ms 724 KB Output is correct
7 Correct 1 ms 724 KB Output is correct
8 Correct 22 ms 39260 KB Output is correct
9 Correct 23 ms 39316 KB Output is correct
10 Correct 23 ms 39248 KB Output is correct
11 Correct 25 ms 39336 KB Output is correct
12 Runtime error 1100 ms 133444 KB Execution killed with signal 11
13 Halted 0 ms 0 KB -