Submission #677686

# Submission time Handle Problem Language Result Execution time Memory
677686 2023-01-04T07:18:15 Z mjhmjh1104 Seesaw (JOI22_seesaw) C++17
0 / 100
0 ms 256 KB
#include <cstdio>
#include <numeric>
#include <algorithm>
using namespace std;

int n, a[200006];

double f() {
    long long sum = accumulate(a, a + n, 0LL);
    double init = sum / (double)n, curr = init;
    double mx = curr, mn = curr;
    int l = 0, r = n - 1, cnt = n;
    while (l < r) {
        if (curr < init) sum -= a[l++];
        else sum -= a[r--];
        cnt--;
        curr = sum / (double)cnt;
        mx = max(mx, curr);
        mn = min(mn, curr);
    }
    return mx - mn;
}

double g() {
    long long sum = accumulate(a, a + n, 0LL);
    double init = sum / (double)n, curr = init;
    double mx = curr, mn = curr;
    int l = 0, r = n - 1, cnt = n;
    while (l < r) {
        if (curr > init) sum -= a[r--];
        else sum -= a[l++];
        cnt--;
        curr = sum / (double)cnt;
        mx = max(mx, curr);
        mn = min(mn, curr);
    }
    return mx - mn;
}

int main() {
    scanf("%d", &n);
    for (int i = 0; i < n; i++) scanf("%d", a + i);
    printf("%.10f", min(f(), g()));
}

Compilation message

seesaw.cpp: In function 'int main()':
seesaw.cpp:41:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   41 |     scanf("%d", &n);
      |     ~~~~~^~~~~~~~~~
seesaw.cpp:42:38: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   42 |     for (int i = 0; i < n; i++) scanf("%d", a + i);
      |                                 ~~~~~^~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Incorrect 0 ms 256 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Incorrect 0 ms 256 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Incorrect 0 ms 256 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Incorrect 0 ms 256 KB Output isn't correct
4 Halted 0 ms 0 KB -