結果

問題 No.2389 Cheating Code Golf
ユーザー LyricalMaestro
提出日時 2025-08-08 00:45:54
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 188 ms / 2,000 ms
コード長 899 bytes
コンパイル時間 1,905 ms
コンパイル使用メモリ 81,788 KB
実行使用メモリ 78,704 KB
最終ジャッジ日時 2025-08-08 00:46:03
合計ジャッジ時間 6,127 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 50
権限があれば一括ダウンロードができます

ソースコード

diff #

## https://yukicoder.me/problems/no/2389


def main():
    N, M = map(int, input().split())
    abp = []
    for _ in range(N):
        a, b, p = map(int, input().split())
        abp.append((a, b, p))
    
    exp = [[0] * (2 ** N) for _ in range(M + 2)]
    for m in reversed(range(M + 1)):
        for bit in reversed(range(2 ** N)):

            for i in range(N):
                if (1 << i) & bit == 0:
                    a, b, p = abp[i]
                    new_bit = bit | (1 << i)

                    # ちゃんと解く
                    x1 = (1 / a) + exp[m][new_bit]

                    # 乱択で解く
                    x2 = 0
                    if m < M:
                        x2 = (((1 / b) + exp[m][new_bit]) / p) + ((p - 1) * exp[m + 1][bit] / p)

                    exp[m][bit] = max(x1, x2, exp[m][bit])
    print(exp[0][0])




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