結果
| 問題 |
No.2389 Cheating Code Golf
|
| コンテスト | |
| ユーザー |
lam6er
|
| 提出日時 | 2025-03-31 17:47:29 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
AC
|
| 実行時間 | 1,048 ms / 2,000 ms |
| コード長 | 1,588 bytes |
| コンパイル時間 | 199 ms |
| コンパイル使用メモリ | 82,116 KB |
| 実行使用メモリ | 143,896 KB |
| 最終ジャッジ日時 | 2025-03-31 17:48:45 |
| 合計ジャッジ時間 | 11,362 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 50 |
ソースコード
import sys
from functools import lru_cache
def main():
input = sys.stdin.read().split()
idx = 0
N = int(input[idx])
M = int(input[idx+1])
idx += 2
problems = []
for _ in range(N):
A = int(input[idx])
B = int(input[idx+1])
P = int(input[idx+2])
idx += 3
problems.append((A, B, P))
A_inv = [1.0 / A for A, _, _ in problems]
B_inv = [1.0 / B for _, B, _ in problems]
P_fail = [((P - 1) / P) for _, _, P in problems]
P_success = [1.0 / P for _, _, P in problems]
@lru_cache(maxsize=None)
def dp(mask, m_left):
if mask == (1 << N) - 1:
return 0.0
max_ev = 0.0
for i in range(N):
if not (mask & (1 << i)):
# Option 1: Use deterministic
new_mask = mask | (1 << i)
current_ev = A_inv[i] + dp(new_mask, m_left)
if current_ev > max_ev:
max_ev = current_ev
# Option 2: Try randomized if m_left > 0
if m_left > 0:
s_p = P_success[i]
f_p = P_fail[i]
success_ev = B_inv[i] + dp(mask | (1 << i), m_left)
failure_ev = dp(mask, m_left - 1)
current_ev_rand = s_p * success_ev + f_p * failure_ev
if current_ev_rand > max_ev:
max_ev = current_ev_rand
return max_ev
result = dp(0, M)
print("{0:.15f}".format(result))
if __name__ == '__main__':
main()
lam6er