답안 #677688

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
677688 2023-01-04T07:27:20 Z mjhmjh1104 Seesaw (JOI22_seesaw) C++17
1 / 100
72 ms 264 KB
#include <cstdio>
#include <numeric>
#include <algorithm>
using namespace std;

int n, a[200006];

int main() {
    scanf("%d", &n);
    for (int i = 0; i < n; i++) scanf("%d", a + i);
    double res = 1 / 0.;
    for (int i = 0; i < 1 << n; i++) {
        int l = 0, r = n - 1;
        long long sum = accumulate(a, a + n, 0LL);
        int cnt = n;
        double curr = sum / (double)cnt;
        double mx = curr, mn = curr;
        for (int j = 0; j < n; j++) {
            if (i & 1 << j) sum -= a[l++];
            else sum -= a[r--];
            cnt--;
            curr = sum / (double)cnt;
            mx = max(mx, curr);
            mn = min(mn, curr);
        }
        res = min(res, mx - mn);
    }
    printf("%.10f", res);
}

Compilation message

seesaw.cpp: In function 'int main()':
seesaw.cpp:9:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
    9 |     scanf("%d", &n);
      |     ~~~~~^~~~~~~~~~
seesaw.cpp:10:38: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   10 |     for (int i = 0; i < n; i++) scanf("%d", a + i);
      |                                 ~~~~~^~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 72 ms 212 KB Output is correct
3 Correct 71 ms 264 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 72 ms 212 KB Output is correct
3 Correct 71 ms 264 KB Output is correct
4 Incorrect 0 ms 212 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 72 ms 212 KB Output is correct
3 Correct 71 ms 264 KB Output is correct
4 Incorrect 0 ms 212 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 72 ms 212 KB Output is correct
3 Correct 71 ms 264 KB Output is correct
4 Incorrect 0 ms 212 KB Output isn't correct
5 Halted 0 ms 0 KB -