提出 #61244382


ソースコード 拡げる

// Go in my style.
// Not afraid to dark.

#include <bits/stdc++.h>
using namespace std;

clock_t sttime;
#define STCLOCK sttime = clock ();
#define TIMENOW fprintf (stderr, "\nNOW TIME COSSEMED: %0.4lf\n", 1.0 * (clock () - sttime) / CLOCKS_PER_SEC);
#define inline __inline__ __attribute__ ((always_inline))

const int N = 2e5;
const long double eps = 1e-11;
int n;
long double a[N + 5], b[N + 5], c[N + 5], f[N + 5];
int sta[N + 5], top;

inline long double Cal (int x, int y, int z){ return a[x] * (y - z) / (y - x) + a[y] * (x - z) / (x - y); }
inline bool Cmp (long double x, long double y){ return (y - x) > eps; }

inline void lbread (long double &x){ double y; scanf ("%lf", &y); x = y; }

signed main (){
    STCLOCK

    scanf ("%d", &n);
    int id = 1;
    for (int i = 1;i <= n;++ i){
        lbread (a[i]);
        if (a[id] < a[i]) id = i;
    }
    for (int i = 1;i <= n;++ i) b[i] = a[(i + id - 2) % n + 1];
    for (int i = 1;i <= n;++ i) a[i] = b[i];
    for (int i = 1;i <= n;++ i) lbread (b[(i - id + n) % n + 1]);
    for (int i = 2;i <= n;++ i) c[2] -= 1.0 * (n + 1 - i) * b[i] * 2;
    a[n + 1] = a[1], b[n + 1] = b[1];
    c[1] = 0; c[2] /= n;
    for (int i = 3;i <= n;++ i) c[i] = c[i - 1] * 2 - c[i - 2] + 2 * b[i - 1];
    for (int i = 2;i <= n;++ i) a[i] -= c[i];
    sta[top = 1] = 1; a[n + 1] = a[1];
    for (int i = 2;i <= n + 1;++ i){
        while (top > 1 && Cmp (a[sta[top]], Cal (sta[top - 1], i, sta[top]))) -- top;
        sta[++ top] = i;
    }
    for (int i = 1;i < top;++ i)
        for (int j = sta[i];j < sta[i + 1];++ j)
            f[j] = Cal (sta[i], sta[i + 1], j) + c[j];
    long double ans = 0;
    for (int i = 1;i <= n;++ i) ans += f[i];
    printf ("%0.14lf\n", (double) (ans / n));

    TIMENOW
    return 0;
}

提出情報

提出日時
問題 E - Random Pawn
ユーザ good88
言語 C++ 20 (gcc 12.2)
得点 1300
コード長 1822 Byte
結果 AC
実行時間 48 ms
メモリ 17112 KiB

コンパイルエラー

Main.cpp: In function ‘int main()’:
Main.cpp:26:11: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   26 |     scanf ("%d", &n);
      |     ~~~~~~^~~~~~~~~~
Main.cpp: In function ‘void lbread(long double&)’:
Main.cpp:21:54: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   21 | inline void lbread (long double &x){ double y; scanf ("%lf", &y); x = y; }
      |                                                ~~~~~~^~~~~~~~~~~

ジャッジ結果

セット名 Sample All
得点 / 配点 0 / 0 1300 / 1300
結果
AC × 4
AC × 20
セット名 テストケース
Sample example0.txt, example1.txt, example2.txt, example3.txt
All 000.txt, 001.txt, 002.txt, 003.txt, 004.txt, 005.txt, 006.txt, 007.txt, 008.txt, 009.txt, 010.txt, 011.txt, 012.txt, 013.txt, 014.txt, 015.txt, example0.txt, example1.txt, example2.txt, example3.txt
ケース名 結果 実行時間 メモリ
000.txt AC 1 ms 3780 KiB
001.txt AC 1 ms 3804 KiB
002.txt AC 48 ms 16404 KiB
003.txt AC 44 ms 16348 KiB
004.txt AC 9 ms 7092 KiB
005.txt AC 9 ms 7284 KiB
006.txt AC 43 ms 16444 KiB
007.txt AC 11 ms 7048 KiB
008.txt AC 11 ms 6928 KiB
009.txt AC 45 ms 16552 KiB
010.txt AC 45 ms 17072 KiB
011.txt AC 44 ms 16860 KiB
012.txt AC 44 ms 16416 KiB
013.txt AC 44 ms 16844 KiB
014.txt AC 45 ms 17112 KiB
015.txt AC 45 ms 16928 KiB
example0.txt AC 1 ms 3972 KiB
example1.txt AC 1 ms 3972 KiB
example2.txt AC 1 ms 3964 KiB
example3.txt AC 1 ms 3804 KiB