# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
1067376 | 2024-08-20T16:00:53 Z | TimDee | Seesaw (JOI22_seesaw) | C++17 | 59 ms | 12268 KB |
#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
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 348 KB | Output is correct |
2 | Correct | 0 ms | 348 KB | Output is correct |
3 | Correct | 0 ms | 348 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 348 KB | Output is correct |
2 | Correct | 0 ms | 348 KB | Output is correct |
3 | Correct | 0 ms | 348 KB | Output is correct |
4 | Correct | 0 ms | 348 KB | Output is correct |
5 | Correct | 0 ms | 348 KB | Output is correct |
6 | Correct | 0 ms | 348 KB | Output is correct |
7 | Correct | 0 ms | 348 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 348 KB | Output is correct |
2 | Correct | 0 ms | 348 KB | Output is correct |
3 | Correct | 0 ms | 348 KB | Output is correct |
4 | Correct | 0 ms | 348 KB | Output is correct |
5 | Correct | 0 ms | 348 KB | Output is correct |
6 | Correct | 0 ms | 348 KB | Output is correct |
7 | Correct | 0 ms | 348 KB | Output is correct |
8 | Correct | 1 ms | 604 KB | Output is correct |
9 | Correct | 1 ms | 604 KB | Output is correct |
10 | Correct | 1 ms | 604 KB | Output is correct |
11 | Correct | 1 ms | 604 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 348 KB | Output is correct |
2 | Correct | 0 ms | 348 KB | Output is correct |
3 | Correct | 0 ms | 348 KB | Output is correct |
4 | Correct | 0 ms | 348 KB | Output is correct |
5 | Correct | 0 ms | 348 KB | Output is correct |
6 | Correct | 0 ms | 348 KB | Output is correct |
7 | Correct | 0 ms | 348 KB | Output is correct |
8 | Correct | 1 ms | 604 KB | Output is correct |
9 | Correct | 1 ms | 604 KB | Output is correct |
10 | Correct | 1 ms | 604 KB | Output is correct |
11 | Correct | 1 ms | 604 KB | Output is correct |
12 | Correct | 52 ms | 12268 KB | Output is correct |
13 | Correct | 59 ms | 12232 KB | Output is correct |
14 | Correct | 59 ms | 12248 KB | Output is correct |
15 | Correct | 53 ms | 12228 KB | Output is correct |
16 | Correct | 59 ms | 12108 KB | Output is correct |