結果

問題 No.3318 客に卵をかける
コンテスト
ユーザー Andrew8128
提出日時 2025-08-05 21:11:12
言語 PyPy3
(7.3.15)
結果
RE  
実行時間 -
コード長 1,185 bytes
コンパイル時間 232 ms
コンパイル使用メモリ 82,592 KB
実行使用メモリ 67,420 KB
最終ジャッジ日時 2025-10-26 11:39:23
合計ジャッジ時間 846 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample RE * 1
other RE * 2
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
import math

def f(x, Q, R, remain, p):
    if p == 1.0:
        b = Q * remain
    else:
        b = Q * ((1.0 - pow(p, x)) / (1.0 - p))
    a = (remain - x) * (Q - (1.0 - p) * R)
    return a + b

def main():
    N = int(sys.stdin.readline())
    X, Y = map(int, sys.stdin.readline().split())
    P, Q, R = map(float, sys.stdin.readline().split())

    ans = -1.0

    for t in range(N + 1):
        skill = X + t * Y
        remain = N - t

        if skill == 1:
            if remain == 1:
                ans = max(ans, P * t + Q)
            else:
                ans = max(ans, P * t + (Q - R) * (remain - 1) + Q)
            continue

        p = 1.0 - 1.0 / skill

        left = 0
        right = remain
        while right - left >= 3:
            cl = (left * 2 + right) // 3
            cr = (left + right * 2) // 3
            fcl = f(cl, Q, R, remain, p)
            fcr = f(cr, Q, R, remain, p)
            if fcl < fcr:
                left = cl
            else:
                right = cr

        for i in range(left, right + 1):
            ans = max(ans, P * t + f(i, Q, R, remain, p))

    print(f"{ans:.10f}")

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