답안 #855628

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
855628 2023-10-01T14:30:36 Z MisterReaper Seesaw (JOI22_seesaw) C++17
0 / 100
0 ms 348 KB
//Bismillahirrahmanirrahim...
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
 
//author: Ahmet Alp Orakci
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
 
#define ONLINE_JUDGE
void solve() {
    int n;
    cin >> n;
 
    vector <int> vec(n +1);
    for(int i = 1; i <= n; i++)
        cin >> vec[i];

    i64 top = accumulate(vec.begin(), vec.end(), 0LL);
    vector <double> can;

    int l = 1, r = 1;
    i64 sum = vec[l];
    while(r <= n) {
        //cerr << l << " " << r << " :: " << sum << "\n";
        if(r < l) {
            r++;
            sum = vec[r];
            continue;
        }

        can.emplace_back(double(1) * sum / (r - l +1));
        if(double(1) * (sum - vec[l]) / (r - l +1) <= double(1) * top / (r - l +1)) {
            r++;
            sum += vec[r];
        } else {
            sum -= vec[l];
            l++;
        }
    }
 
    double ans = vec[n] - vec[1];
    for(double &mx : can) {
        i64 sum = top; 
 
        double mn = double(1) * sum / n;
        if(mn > mx) {
            continue;
        }
 
        int l = 1, r = n;
        while(l < r) {
            //cerr << l << " " << r << "\n";
            if(sum - vec[l] <= mx * (r - l)) {
                sum -= vec[l];
                l++;
            } else {
                sum -= vec[r];
                r--;
            }
 
            mn = min(mn, double(1) * sum / (r - l +1));

            if(mx - mn >= ans) {
                break;
            }
        }
 
        //cerr << "# " << mx << " " << mn << "\n";
        ans = min(ans, mx - mn);
        //cerr << "\n";
    }
 
    cout << setprecision(15) << ans;
    
    return;
}
 
signed main() {
    #ifndef ONLINE_JUDGE
        freopen(".in", "r", stdin);
        freopen(".out", "w", stdout);
    #endif
 
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
 
    int t = 1; //cin >> t;
    for(int i = 1; i <= t; i++) {
        solve();
    }
 
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Incorrect 0 ms 348 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Incorrect 0 ms 348 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Incorrect 0 ms 348 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Incorrect 0 ms 348 KB Output isn't correct
3 Halted 0 ms 0 KB -