Submission #1067376

#TimeUsernameProblemLanguageResultExecution timeMemory
1067376TimDeeSeesaw (JOI22_seesaw)C++17
100 / 100
59 ms12268 KiB
#include <bits/stdc++.h> using namespace std; #define int long long #define forn(i,n) for(int i=0; i<n; ++i) #define vii(a,n) vector<int> a(n); forn(i,n) cin>>a[i]; #define f first #define s second #define pb push_back #define all(x) x.begin(),x.end() const double eps = 1e-9; void solve() { int n; cin>>n; vii(a,n); vector<pair<double,int>> v; int s=0; forn(i,n) s+=a[i]; double c = 1.0*s/n; int l=0, r=n-1; while (l<=r) { int m=r-l+1; v.pb({1.0*s/m,m-1}); if (l==r) break; double z = 1.0*(s-a[r])/(m-1); if (z>=c) { s-=a[r]; --r; } else { s-=a[l]; ++l; } } s=0, l=0, r=n-1; forn(i,n) s+=a[i]; while (l<=r) { int m=r-l+1; v.pb({1.0*s/m,m-1}); if (l==r) break; double z = 1.0*(s-a[l])/(m-1); if (z<=c) { s-=a[l]; ++l; } else { s-=a[r]; --r; } } sort(all(v)); //for(auto&x:v) cout<<'('<<x.f<<','<<x.s<<") "; vector<int> cnt(n); int tot=0; r=0; double ans=a[n-1]-a[0]; forn(i,v.size()) { while (r<v.size() && tot<n) { tot+=!cnt[v[r].s]; ++cnt[v[r].s]; ++r; } if (tot==n) ans=min(ans,v[r-1].f - v[i].f); --cnt[v[i].s]; tot-=!cnt[v[i].s]; } cout<<fixed<<setprecision(10)<<ans<<'\n'; } int32_t main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); solve(); }

Compilation message (stderr)

seesaw.cpp: In function 'void solve()':
seesaw.cpp:5:33: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<double, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    5 | #define forn(i,n) for(int i=0; i<n; ++i)
......
   52 |  forn(i,v.size()) {
      |       ~~~~~~~~~~                 
seesaw.cpp:52:2: note: in expansion of macro 'forn'
   52 |  forn(i,v.size()) {
      |  ^~~~
seesaw.cpp:53:11: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<double, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   53 |   while (r<v.size() && tot<n) {
      |          ~^~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...