Submission #1144258

#TimeUsernameProblemLanguageResultExecution timeMemory
1144258Noproblem29Seesaw (JOI22_seesaw)C++20
67 / 100
206 ms19432 KiB
#include<bits/stdc++.h> using namespace std; #ifndef BADGNU #pragma GCC target("sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native") #endif #pragma GCC optimize("Ofast,unroll-loops,fast-math,O3") #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace __gnu_pbds; #define ll long long #define int ll #define ld long double #define y1 cheza mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); template<class T> using ordered_set = tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>; template<class T> using ordered_multiset = tree<T,null_type,less_equal<T>,rb_tree_tag,tree_order_statistics_node_update>; const int N=2e5+100; const int M=5001; const int B=447; const int mod=998244353; const ll INF=1e18; const int dx[]={1,-1,0,0}; const int dy[]={0,0,1,-1}; const double eps=1e-6; int n; int a[N]; int pref[N]; struct ki{ int first,second; }; bool operator<(const ki&x,const ki&y){ return x.first*y.second<y.first*x.second; } bool operator<=(const ki&x,const ki&y){ return x.first*y.second<=y.first*x.second; } bool operator>(const ki&x,const ki&y){ return x.first*y.second>y.first*x.second; } bool operator>=(const ki&x,const ki&y){ return x.first*y.second>=y.first*x.second; } bool operator==(const ki&x,const ki&y){ return x.first*y.second==y.first*x.second; } ki operator-(const ki&x,const ki&y){ ki res={(x.first*y.second-y.first*x.second),(x.second*y.second)}; // int g=gcd(res.first,res.second); // res.first/=g; // res.second/=g; return res; } ki max(const ki&x,const ki&y){ if(x<y){ return y; } return x; } ki min(const ki&x,const ki&y){ if(x>y){ return y; } return x; } ki calc(int l,int r){ return {pref[r]-pref[l-1],(r-l+1)}; } ki ans={1000000000,1}; void test(){ cin>>n; for(int i=1;i<=n;i++){ cin>>a[i]; pref[i]=pref[i-1]+a[i]; } set<tuple<ki,int,int>>s; int l=1; int r=n; ki mx=calc(1,n); while(1){ s.insert({calc(l,r),l,r}); if(l==r)break; if(calc(l+1,r)<=mx)l++; else r--; } while(1){ auto [w,tl,tr]=*s.begin(); s.erase(s.begin()); ans=min(ans,mx-w); if(tr==n)break; s.insert({calc(tl+1,tr+1),tl+1,tr+1}); mx=max(mx,calc(tl+1,tr+1)); } ld res=ans.first/((ld)ans.second); cout<<fixed; cout<<setprecision(10); cout<<res<<'\n'; } /* */ signed main(){ ios_base::sync_with_stdio(false); cin.tie(nullptr); // cout.tie(nullptr); int t2=1; // cin>>t2; for(int i=1;i<=t2;i++){ test(); } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...