結果
問題 |
No.58 イカサマなサイコロ
|
ユーザー |
![]() |
提出日時 | 2025-03-20 21:15:54 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 42 ms / 5,000 ms |
コード長 | 1,755 bytes |
コンパイル時間 | 171 ms |
コンパイル使用メモリ | 82,532 KB |
実行使用メモリ | 60,512 KB |
最終ジャッジ日時 | 2025-03-20 21:16:41 |
合計ジャッジ時間 | 1,260 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 10 |
ソースコード
n = int(input()) k = int(input()) max_sum = 6 * n # Calculate Jiro's probability distribution (normal dice) jiro_dp = [0.0] * (max_sum + 1) jiro_dp[0] = 1.0 for _ in range(n): next_dp = [0.0] * (max_sum + 1) for s in range(max_sum + 1): if jiro_dp[s] == 0: continue prob = jiro_dp[s] / 6 for d in range(1, 7): next_sum = s + d if next_sum > max_sum: continue next_dp[next_sum] += prob jiro_dp = next_dp # Calculate Taro's probability distribution (K loaded and N-K normal dice) taro_dp = [0.0] * (max_sum + 1) taro_dp[0] = 1.0 # Process K loaded dice for _ in range(k): next_taro = [0.0] * (max_sum + 1) for s in range(max_sum + 1): if taro_dp[s] == 0: continue prob = taro_dp[s] / 3 for d in [4, 5, 6]: next_sum = s + d if next_sum > max_sum: continue next_taro[next_sum] += prob taro_dp = next_taro # Process N-K normal dice for _ in range(n - k): next_taro = [0.0] * (max_sum + 1) for s in range(max_sum + 1): if taro_dp[s] == 0: continue prob = taro_dp[s] / 6 for d in range(1, 7): next_sum = s + d if next_sum > max_sum: continue next_taro[next_sum] += prob taro_dp = next_taro # Calculate the total winning probability total = 0.0 for s in range(max_sum + 1): prob_taro = taro_dp[s] if prob_taro == 0: continue # Sum of Jiro's probabilities where his sum is less than s prob_jiro_less = sum(jiro_dp[:s]) total += prob_taro * prob_jiro_less # Print the result with five decimal places print("{0:.5f}".format(total))