結果
問題 | No.463 魔法使いのすごろく🎲 |
ユーザー |
![]() |
提出日時 | 2025-03-26 15:45:23 |
言語 | PyPy3 (7.3.15) |
結果 |
RE
|
実行時間 | - |
コード長 | 1,946 bytes |
コンパイル時間 | 196 ms |
コンパイル使用メモリ | 81,920 KB |
実行使用メモリ | 77,576 KB |
最終ジャッジ日時 | 2025-03-26 15:46:10 |
合計ジャッジ時間 | 9,076 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 35 RE * 1 |
ソースコード
n, m = map(int, input().split())c = list(map(int, input().split()))def move(i, k, n):total = i + kif total <= n:return totalover = total - ncycle = 2 * (n - 1)over %= cycleif over == 0:return nif over <= (n - 1):return n - overelse:return over - (n - 1) + 1eps = 1e-12max_iter = 1000000DPA = [0.0] * (n + 1)DPB = [0.0] * (n + 1)for _ in range(max_iter):next_DPA = DPA.copy()next_DPB = DPB.copy()converged = Truefor i in range(n, 0, -1):if i == n:next_DPA[i] = 0.0next_DPB[i] = 0.0continue# Calculate DPB[i]sum_b = 0.0for k in range(1, m + 1):j = move(i, k, n)if 2 <= j <= n - 1:cost = c[j - 2]else:cost = 0sum_b += cost + DPB[j]new_dpb = sum_b / mif abs(new_dpb - next_DPB[i]) > eps:converged = Falsenext_DPB[i] = new_dpb# Calculate DPA[i]sum_a = 0.0for k in range(1, m + 1):j = move(i, k, n)if 2 <= j <= n - 1:cost = c[j - 2]else:cost = 0sum_a += cost + DPA[j]val_normal = sum_a / mval_magic = float('inf')for k in range(1, m + 1):j = move(i, k, n)if 2 <= j <= n - 1:cost = c[j - 2]else:cost = 0current = cost + DPB[j]if current < val_magic:val_magic = currentnew_dpa = min(val_normal, val_magic)if abs(new_dpa - next_DPA[i]) > eps:converged = Falsenext_DPA[i] = new_dpaDPA, next_DPA = next_DPA, DPADPB, next_DPB = next_DPB, DPBif converged:breakprint("{0:.10f}".format(DPA[1]))