Submission #855569

# Submission time Handle Problem Language Result Execution time Memory
855569 2023-10-01T12:43:50 Z MisterReaper Seesaw (JOI22_seesaw) C++17
0 / 100
2 ms 344 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];

    vector <double> can;
    for(int i = 1; i <= n; i++) {
        i64 sum = 0;
        for(int j = i; j <= n; j++) {
            sum += vec[j];
            can.emplace_back(double(1) * sum / (j - i +1));
        }
    }

    i64 top = accumulate(vec.begin(), vec.end(), 0LL);
    double ans = 1E18;
    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));
        }

        //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;
}

Compilation message

seesaw.cpp: In function 'int main()':
seesaw.cpp:64:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   64 |         freopen(".in", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~
seesaw.cpp:65:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   65 |         freopen(".out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 344 KB Unexpected end of file - double expected
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 344 KB Unexpected end of file - double expected
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 344 KB Unexpected end of file - double expected
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 344 KB Unexpected end of file - double expected
2 Halted 0 ms 0 KB -