結果
問題 | No.248 ミラー君の宿題 |
ユーザー | maspy |
提出日時 | 2020-05-13 23:16:53 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 2,060 bytes |
コンパイル時間 | 335 ms |
コンパイル使用メモリ | 82,056 KB |
実行使用メモリ | 78,072 KB |
最終ジャッジ日時 | 2024-09-14 15:44:57 |
合計ジャッジ時間 | 7,828 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | WA | - |
testcase_01 | WA | - |
testcase_02 | WA | - |
testcase_03 | WA | - |
testcase_04 | WA | - |
testcase_05 | WA | - |
testcase_06 | WA | - |
testcase_07 | WA | - |
testcase_08 | WA | - |
testcase_09 | WA | - |
testcase_10 | WA | - |
testcase_11 | WA | - |
testcase_12 | WA | - |
testcase_13 | WA | - |
testcase_14 | WA | - |
testcase_15 | WA | - |
testcase_16 | WA | - |
testcase_17 | WA | - |
ソースコード
import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines def ord_2(n): e = 0 while n % 2 == 0: e += 1 n >>= 1 return e def argmax_distribution(A): U = max(A) n = len(A) dist = [0] * (1<<n) full = (1<<n) - 1 dist[full] += 0.5 ** sum(A) for u in range(1, U+1): eq = [0.0] * (1<<n) low = [0.0] * (1<<n) eq[0] = 1.0 low[0] = 1.0 for i in range(n): t = 0.5 ** (A[i] - u + 1) p_eq = t if A[i] >= u else 0.0 p_low = t if u <= A[i] + 1 else 1.0 for s in range(1<<i): eq[s^(1<<i)] = eq[s] * p_eq low[s^(1<<i)] = low[s] * p_low for s in range(1, 1<<n): dist[s] += eq[s] * low[full^s] return dist def solve(nums): N = len(nums) dp = [0.0] * (1<<N) A = [ord_2(p-1) for p in nums] def compute_dp(s): if s == 0: return 0.0 I = [i for i in range(N) if s & (1<<i)] n = len(I) if n == 1: return 1.0 p_loop = 0 x = 1.0 # gcd で遷移する場合 gcd_prob = [1.0] * (1<<n) ind = [0] * (1<<n) for k in range(n): i = I[k] for j in range(1<<k): ind[j + (1<<k)] = ind[j] + (1<<i) gcd_prob[j + (1<<k)] = gcd_prob[j] / (nums[i]) gcd_prob[j] -= gcd_prob[j + (1<<k)] p_loop += gcd_prob[-1] B = [A[i] for i in I] for j in range((1<<n) - 1): x += gcd_prob[j] * (dp[ind[j]] + dp[s^ind[j]]) # 2^n乗根で遷移する場合 p0 = gcd_prob[0] dist = argmax_distribution([A[i] for i in I]) p_loop += p0 * dist[-1] for j in range((1<<n) - 1): x += p0 * dist[j] * (dp[ind[j]] + dp[s^ind[j]]) return x / (1 - p_loop) for s in range(1<<N): dp[s] = compute_dp(s) return dp[-1] solve([3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43])