結果

問題 No.2009 Drunkers' Contest
ユーザー lam6er
提出日時 2025-03-20 20:53:15
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 329 ms / 2,000 ms
コード長 941 bytes
コンパイル時間 148 ms
コンパイル使用メモリ 82,356 KB
実行使用メモリ 150,940 KB
最終ジャッジ日時 2025-03-20 20:54:12
合計ジャッジ時間 10,362 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 54
権限があれば一括ダウンロードができます

ソースコード

diff #

import math

n = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
groups = []

for a, b in zip(A, B):
    new_sum_A = a
    new_sum_B = b
    ratio = new_sum_A / new_sum_B
    x = math.sqrt(ratio) - 1
    if x < 0:
        x = 0.0
    groups.append((new_sum_A, new_sum_B, x))
    while len(groups) >= 2 and groups[-2][2] > groups[-1][2]:
        # Merge the last two groups
        sumA1, sumB1, x1 = groups[-2]
        sumA2, sumB2, x2 = groups[-1]
        merged_sumA = sumA1 + sumA2
        merged_sumB = sumB1 + sumB2
        merged_ratio = merged_sumA / merged_sumB
        merged_x = math.sqrt(merged_ratio) - 1
        if merged_x < 0:
            merged_x = 0.0
        groups.pop()
        groups.pop()
        groups.append((merged_sumA, merged_sumB, merged_x))

total = 0.0
for sumA, sumB, x in groups:
    denom = 1 + x
    total += sumA / denom + sumB * denom

print("{0:.10f}".format(total))
0