Submission #739727

# Submission time Handle Problem Language Result Execution time Memory
739727 2023-05-11T07:01:07 Z alexdd Seesaw (JOI22_seesaw) C++17
34 / 100
299 ms 33340 KB
#include<bits/stdc++.h>
using namespace std;
//ifstream fin("seesaw.in");
//#define cin fin
#define double long double
vector<double> ord;
int n;
int a[200005];
double tot,ans=1000000000;
double verif(double le)///lungimea minima daca barycentrul nu poate trece in stanga lui le
{
    double sum = tot,mxm;
    int pozs=1,pozd=n;
    //mxm = tot/n;
    mxm = tot/n;
    for(int i=1;i<=n-1;i++)
    {
        if((sum-a[pozd])/(n-i)>=le)
        {
            sum-=a[pozd];
            pozd--;
        }
        else
        {
            sum-=a[pozs];
            pozs++;
        }
        mxm = max(mxm, sum/(n-i));
        //cout<<fixed<<setprecision(15)<<sum/(n-i)<<"\n";
    }
    ans = min(ans, mxm-le);
    return mxm-le;
}
signed main()
{
    ios_base::sync_with_stdio(0);cin.tie(0);

    cin>>n;
    for(int i=1;i<=n;i++)
    {
        cin>>a[i];
        tot+=a[i];
    }
    for(int i=1;i<=n;i++)
    {
        double cv = 0;
        for(int j=i;j<=n;j++)
        {
            cv += a[j];
            ord.push_back(cv/(j-i+1));
        }
    }
    sort(ord.begin(),ord.end());
    while(ord[ord.size()-1]>tot/n)
        ord.pop_back();
    int st,dr,mij1,mij2;
    st=0;
    dr=ord.size()-1;
    while(dr-st+1>=1000)
    {
        mij1 = st + (dr-st+1)/3;
        mij2 = mij1 + (dr-st+1)/3;
        if(verif(ord[mij1])==verif(ord[mij2]))
        {
            while(1)
                st=dr;
        }
        if(verif(ord[mij1])<verif(ord[mij2]))
            dr=mij2;
        else
            st=mij1;
    }
    //st=0;dr=ord.size()-1;
    for(int i=st;i<=dr;i++)
        ans = min(ans, verif(ord[i]));
    cout<<fixed<<setprecision(15)<<ans;
    return 0;
}
/**


*/
# Verdict Execution time Memory Grader output
1 Correct 2 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 2 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 2 ms 460 KB Output is correct
5 Correct 2 ms 468 KB Output is correct
6 Correct 1 ms 468 KB Output is correct
7 Correct 1 ms 468 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 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 2 ms 460 KB Output is correct
5 Correct 2 ms 468 KB Output is correct
6 Correct 1 ms 468 KB Output is correct
7 Correct 1 ms 468 KB Output is correct
8 Correct 299 ms 33332 KB Output is correct
9 Correct 290 ms 33340 KB Output is correct
10 Correct 289 ms 33324 KB Output is correct
11 Incorrect 291 ms 33336 KB Output isn't correct
12 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 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 2 ms 460 KB Output is correct
5 Correct 2 ms 468 KB Output is correct
6 Correct 1 ms 468 KB Output is correct
7 Correct 1 ms 468 KB Output is correct
8 Correct 299 ms 33332 KB Output is correct
9 Correct 290 ms 33340 KB Output is correct
10 Correct 289 ms 33324 KB Output is correct
11 Incorrect 291 ms 33336 KB Output isn't correct
12 Halted 0 ms 0 KB -