Submission #739883

# Submission time Handle Problem Language Result Execution time Memory
739883 2023-05-11T14:00:01 Z finn__ Seesaw (JOI22_seesaw) C
Compilation error
0 ms 0 KB
#include <stdio.h>
#include <stdint.h>
#include <inttypes.h>
#include <stdlib.h>

#define N 200001

int64_t a[N];
double e[N][2];

inline int compare_centers(void const *const u, void const *const v)
{
    return *(double *)u < *(double *)v ? -1 : 1;
}

int main()
{
    size_t n;
    scanf("%zu", &n);
    for (size_t i = 1; i <= n; ++i)
        scanf("%" PRId64, a + i), a[i] += a[i - 1];
    for (size_t k = 0; k < n - 1; ++k)
    {
        size_t u = 1, v = n - k;
        double const y = (double)(k + 1) / n;
        while (u < v)
        {
            size_t const mid = (u + v) / 2;
            if ((a[mid + k] - a[mid - 1]) < (double)a[n] * y)
                u = mid + 1;
            else
                v = mid;
        }
        e[k][0] = (double)(a[u + k] - a[u - 1]) / (k + 1);
        e[k][1] = (double)(a[u + k - 1] - a[u - 2]) / (k + 1);
    }

    e[n - 1][0] = e[n - 1][1] = (double)a[n] / n;
    qsort(e, n, sizeof *e, compare_centers);
    double ans = 1e9, minl = (double)a[n] / n;

    for (size_t i = n - 1; i < n; --i)
    {
        ans = e[i][0] - minl < ans ? e[i][0] - minl : ans;
        minl = e[i][1] < minl ? e[i][1] : minl;
    }

    printf("%.10lf\n", ans);
}

Compilation message

seesaw.c: In function 'main':
seesaw.c:19:5: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   19 |     scanf("%zu", &n);
      |     ^~~~~~~~~~~~~~~~
seesaw.c:21:9: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   21 |         scanf("%" PRId64, a + i), a[i] += a[i - 1];
      |         ^~~~~~~~~~~~~~~~~~~~~~~~
/usr/bin/ld: /tmp/ccDhQvZh.o: in function `main':
seesaw.c:(.text.startup+0x170): undefined reference to `compare_centers'
collect2: error: ld returned 1 exit status