結果
| 問題 |
No.242 ビンゴゲーム
|
| ユーザー |
|
| 提出日時 | 2015-07-11 00:24:38 |
| 言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
| 結果 |
AC
|
| 実行時間 | 26 ms / 2,000 ms |
| コード長 | 2,216 bytes |
| コンパイル時間 | 82 ms |
| コンパイル使用メモリ | 12,800 KB |
| 実行使用メモリ | 11,008 KB |
| 最終ジャッジ日時 | 2024-07-08 02:27:36 |
| 合計ジャッジ時間 | 845 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 8 |
ソースコード
import math
def preprocess():
Bingos = [0] * 26
Counts = [0] * 26
masks12 = get_masks()
for pat in range(2**25):
bits_on = bin(pat).count('1')
Bingos[bits_on] += 12 - len([1 for mask in masks12 if ~pat & mask])
Counts[bits_on] += 1
return [bingo/count for bingo, count in zip(Bingos, Counts)]
def get_masks():
bingo_patterns = [[0, 1, 2, 3, 4],
[5, 6, 7, 8, 9],
[10, 11, 12, 13, 14],
[15, 16, 17, 18, 19],
[20, 21, 22, 23, 24],
[0, 5, 10, 15, 20],
[1, 6, 11, 16, 21],
[2, 7, 12, 17, 22],
[3, 8, 13, 18, 23],
[4, 9, 14, 19, 24],
[0, 6, 12, 18, 24],
[4, 8, 12, 16, 20]]
return [sum(1 << i for i in pat) for pat in bingo_patterns]
# E = preprocess()
# 2秒では計算が終わらなかったので、オフラインで事前に計算しました。。。
E = [0.0, 0.0, 0.0, 0.0, 0.0, 0.00022586109542631282, 0.0013551665725578769, 0.0047430830039525695, 0.012648221343873518, 0.028458498023715414, 0.05691699604743083, 0.10434782608695652, 0.17888198757763976, 0.2906832298136646, 0.45217391304347826, 0.6782608695652174, 0.9865612648221344, 1.3976284584980236, 1.9351778656126482, 2.6263128176171655, 3.501750423489554, 4.59604743083004, 5.947826086956522, 7.6, 9.6, 12.0]
def prob(N):
'''1-99 までの N 個を選んだときに、1-25までの数字が n 個含まれる確率 prob[n] のリストを返す。
1-25から n 個とり、26-99から N-n 個とればよい。
'''
probs = [0] * 26
base = math.factorial(99) // math.factorial(N) // math.factorial(99 - N)
fac25 = math.factorial(25)
fac74 = math.factorial(74)
for n in range(max(0, N - 74), min(25, N) + 1):
pats1_25 = fac25 // math.factorial(n) // math.factorial(25 - n)
pats26_99 = fac74 // math.factorial(N - n) // math.factorial(74 - N + n)
probs[n] = pats1_25 * pats26_99 / base
return probs
N = int(input())
probs = prob(N)
Expected = sum(e * p for e, p in zip(E, probs))
print(Expected)