Submission #777007

# Submission time Handle Problem Language Result Execution time Memory
777007 2023-07-08T13:32:55 Z Rafi22 Seesaw (JOI22_seesaw) C++14
67 / 100
64 ms 13696 KB
#include <bits/stdc++.h>

using namespace std;

#define endl '\n'
#define st first
#define nd second
#define pb push_back
#define sz(x) (int)(x).size()
#define all(x) (x).begin(), (x).end()
#define ll long long
#define ld long double
ll mod=1000000007;
int inf=1000000007;
ll infl=1000000000000000007;

const int N=200007;

ll a[N];
ll P[N];

bool cmp(pair<ll,ll>l,pair<ll,ll>r)
{
    return l.st*r.nd<r.st*l.nd;
}

int cnt[N];

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n;
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        cin>>a[i];
        P[i]=P[i-1]+a[i];
    }
    vector<pair<ll,ll>>V;
    V.pb({P[n],n});
    for(int k=1;k<n;k++)
    {
        int l=1,r=n-k+1,sr,p;
        while(l<=r)
        {
            sr=(l+r)/2;
            if((P[sr+k-1]-P[sr-1])*(ll)n<=P[n]*(ll)k)
            {
                p=sr;
                l=sr+1;
            }
            else r=sr-1;
        }
        V.pb({P[p+k-1]-P[p-1],k});
        if(p+k<=n) V.pb({P[p+k]-P[p],k});
    }
    sort(all(V),cmp);
    ld ans=inf;
    int j=0,ile=0;
    for(int i=0;i<sz(V);i++)
    {
        while(j<sz(V)&&ile<n)
        {
            cnt[V[j].nd]++;
            if(cnt[V[j].nd]==1) ile++;
            j++;
        }
        if(ile==n)
        {
            ans=min(ans,(ld)V[j-1].st/(ld)V[j-1].nd-(ld)V[i].st/(ld)V[i].nd);
        }
        cnt[V[i].nd]--;
        if(cnt[V[i].nd]==0) ile--;
    }
    cout<<fixed<<setprecision(9)<<ans;

    return 0;
}

Compilation message

seesaw.cpp: In function 'int main()':
seesaw.cpp:57:36: warning: 'p' may be used uninitialized in this function [-Wmaybe-uninitialized]
   57 |         if(p+k<=n) V.pb({P[p+k]-P[p],k});
      |                                 ~~~^
# Verdict Execution time Memory Grader output
1 Correct 1 ms 388 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 388 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 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 388 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 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 524 KB Output is correct
9 Correct 1 ms 468 KB Output is correct
10 Correct 1 ms 468 KB Output is correct
11 Correct 1 ms 468 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 388 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 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 524 KB Output is correct
9 Correct 1 ms 468 KB Output is correct
10 Correct 1 ms 468 KB Output is correct
11 Correct 1 ms 468 KB Output is correct
12 Incorrect 64 ms 13696 KB Output isn't correct
13 Halted 0 ms 0 KB -