# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1127007 | gawr_gura | Seesaw (JOI22_seesaw) | C++20 | 62 ms | 328 KiB |
#include <bits/stdc++.h>
using namespace std;
#define int long long
using ii = pair<int, int>;
using tp = tuple<int, int, int>;
const int N = 2e5 + 5;
int n, a[N];
namespace sub1{
int pref[N];
int get(int l, int r){
return pref[r] - pref[l - 1];
}
void solve(){
for(int i = 1; i <= n; i++) pref[i] = pref[i - 1] + a[i];
long double res = 1e18;
for(int msk = 0; msk < (1 << n - 1); msk++){
int L = 1, R = n;
long double mx, mn;
mx = mn = (long double)get(L, R) / n;
for(int i = 0; i < n - 1; i++){
if(msk >> i & 1) R -= 1;
else L += 1;
mx = max(mx, (long double)get(L, R) / (R - L + 1));
mn = min(mn, (long double)get(L, R) / (R - L + 1));
}
res = min(res, mx - mn);
}
cout << setprecision(12) << fixed << res << "\n";
}
}
int32_t main(){
cin.tie(0)->sync_with_stdio(0);
#define task "SEESAW"
if(fopen(task ".inp", "r")){
freopen(task ".inp", "r", stdin);
freopen(task ".out", "w", stdout);
}
cin >> n;
for(int i = 1; i <= n; i++) cin >> a[i];
sub1::solve();
return 0;
}
/*
3
1 2 4
6
1 2 5 6 8 9
*/
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |