結果

問題 No.2009 Drunkers' Contest
ユーザー tamato
提出日時 2022-07-15 22:12:35
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 176 ms / 2,000 ms
コード長 1,112 bytes
コンパイル時間 274 ms
コンパイル使用メモリ 82,048 KB
実行使用メモリ 141,960 KB
最終ジャッジ日時 2024-06-27 18:26:00
合計ジャッジ時間 9,202 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 54
権限があれば一括ダウンロードができます

ソースコード

diff #

mod = 998244353


def main():
    import sys
    from math import sqrt
    input = sys.stdin.readline

    N = int(input())
    A = list(map(int, input().split()))
    B = list(map(int, input().split()))

    st = [(1.0, 0, 0, 0)]
    for a, b in zip(A, B):
        x_new = sqrt(a / b)
        if x_new >= st[-1][0]:
            st.append((x_new, a, b, a / x_new + b * x_new))
        else:
            sa = a
            sb = b
            while st:
                x_old, aa, bb, c = st.pop()
                sa += aa
                sb += bb
                x_new = sqrt(sa / sb)
                if not st:
                    if x_new <= 1:
                        st.append((1.0, sa, sb, sa + sb))
                    else:
                        st.append((x_new, sa, sb, sa / x_new + sb * x_new))
                    break
                else:
                    if x_new >= st[-1][0]:
                        st.append((x_new, sa, sb, sa / x_new + sb * x_new))
                        break
    ans = 0
    for _, _, _, y in st:
        ans += y
    print(ans)


if __name__ == '__main__':
    main()
0