답안 #925339

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
925339 2024-02-11T13:09:53 Z boris_mihov Seesaw (JOI22_seesaw) C++17
1 / 100
1 ms 2396 KB
#include <algorithm>
#include <iostream>
#include <numeric>
#include <iomanip>
#include <cassert>
#include <vector>
#include <queue>
#include <set>

typedef long long llong;
const int MAXN = 200000 + 10;
const int INF  = 2e9;

int n;
int a[MAXN];
llong prefix[MAXN];

long double calc(int l, int r)
{
    return ((long double)(prefix[r] - prefix[l - 1])) / (r - l + 1);
}

long double check(long double from)
{
    long double to = from;
    int l = 1, r = n;
    while (true)
    {
        to = std::max(to, calc(l, r));
        if (l == r)
        {
            break;
        }

        if (calc(l, r - 1) > from)
        {
            r--;
        } else
        {
            l++;
        }
    }

    return to - from;
}

void solve()
{   
    for (int i = 1 ; i <= n ; ++i)
    {
        prefix[i] = prefix[i - 1] + a[i];
    }

    long double l = 0.0, r = calc(1, n), midL, midR;
    for (int i = 0 ; i < 100 ; ++i)
    {
        midL = l + (r - l) / 3.0;
        midR = l + 2 * (r - l) / 3.0;
        if (check(midL) < check(midR)) r = midR;
        else l = midL;
    } 

    std::cout << std::fixed << std::setprecision(10) << check(l) << '\n';
}

void input()
{
    std::cin >> n;
    for (int i = 1 ; i <= n ; ++i)
    {
        std::cin >> a[i];
    }
}

void fastIOI()
{
    std::ios_base :: sync_with_stdio(0);
    std::cout.tie(nullptr);
    std::cin.tie(nullptr);
}   

int main()
{
    fastIOI();
    input();
    solve();

    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Incorrect 1 ms 2396 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Incorrect 1 ms 2396 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Incorrect 1 ms 2396 KB Output isn't correct
5 Halted 0 ms 0 KB -