結果
問題 | No.766 金魚すくい |
ユーザー | maspy |
提出日時 | 2020-02-04 09:45:46 |
言語 | Python3 (3.12.2 + numpy 1.26.4 + scipy 1.12.0) |
結果 |
AC
|
実行時間 | 578 ms / 1,500 ms |
コード長 | 1,555 bytes |
コンパイル時間 | 163 ms |
コンパイル使用メモリ | 12,800 KB |
実行使用メモリ | 55,044 KB |
最終ジャッジ日時 | 2024-09-19 20:30:25 |
合計ジャッジ時間 | 24,310 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 487 ms
44,192 KB |
testcase_01 | AC | 478 ms
44,064 KB |
testcase_02 | AC | 479 ms
44,072 KB |
testcase_03 | AC | 543 ms
44,576 KB |
testcase_04 | AC | 475 ms
44,192 KB |
testcase_05 | AC | 488 ms
44,064 KB |
testcase_06 | AC | 492 ms
43,932 KB |
testcase_07 | AC | 480 ms
44,320 KB |
testcase_08 | AC | 487 ms
44,576 KB |
testcase_09 | AC | 480 ms
44,448 KB |
testcase_10 | AC | 480 ms
44,448 KB |
testcase_11 | AC | 479 ms
44,196 KB |
testcase_12 | AC | 473 ms
44,328 KB |
testcase_13 | AC | 476 ms
43,940 KB |
testcase_14 | AC | 479 ms
44,196 KB |
testcase_15 | AC | 470 ms
44,072 KB |
testcase_16 | AC | 472 ms
44,192 KB |
testcase_17 | AC | 487 ms
44,192 KB |
testcase_18 | AC | 482 ms
44,316 KB |
testcase_19 | AC | 478 ms
44,572 KB |
testcase_20 | AC | 475 ms
43,936 KB |
testcase_21 | AC | 473 ms
44,536 KB |
testcase_22 | AC | 469 ms
44,444 KB |
testcase_23 | AC | 523 ms
54,036 KB |
testcase_24 | AC | 578 ms
54,364 KB |
testcase_25 | AC | 527 ms
55,044 KB |
testcase_26 | AC | 524 ms
54,664 KB |
testcase_27 | AC | 525 ms
54,592 KB |
testcase_28 | AC | 518 ms
54,228 KB |
testcase_29 | AC | 533 ms
54,180 KB |
testcase_30 | AC | 521 ms
54,300 KB |
testcase_31 | AC | 527 ms
54,616 KB |
testcase_32 | AC | 524 ms
54,240 KB |
testcase_33 | AC | 512 ms
50,764 KB |
testcase_34 | AC | 510 ms
51,292 KB |
testcase_35 | AC | 490 ms
47,076 KB |
testcase_36 | AC | 498 ms
46,368 KB |
testcase_37 | AC | 520 ms
54,576 KB |
testcase_38 | AC | 546 ms
54,628 KB |
testcase_39 | AC | 529 ms
54,952 KB |
testcase_40 | AC | 527 ms
54,248 KB |
testcase_41 | AC | 520 ms
54,404 KB |
testcase_42 | AC | 521 ms
54,668 KB |
testcase_43 | AC | 470 ms
44,316 KB |
testcase_44 | AC | 476 ms
44,068 KB |
ソースコード
import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines import numpy as np MOD = 10**9 + 7 def cumprod(A, MOD = MOD): L = len(A); Lsq = int(L**.5+1) A = np.resize(A, Lsq**2).reshape(Lsq,Lsq) for n in range(1,Lsq): A[:,n] *= A[:,n-1]; A[:,n] %= MOD for n in range(1,Lsq): A[n] *= A[n-1,-1]; A[n] %= MOD return A.ravel()[:L] def make_fact(U, MOD = MOD): x = np.arange(U, dtype = np.int64); x[0] = 1 fact = cumprod(x, MOD) x = np.arange(U, 0, -1, dtype=np.int64); x[0] = pow(int(fact[-1]), MOD-2, MOD) fact_inv = cumprod(x, MOD)[::-1] fact.flags.writeable = False fact_inv.flags.writeable = False return fact,fact_inv def make_power(a, L, MOD=MOD): B = L.bit_length() x = np.empty((1<<B), np.int64) x[0] = 1 for n in range(B): x[1<<n:1<<(n+1)] = x[:1<<n] * a % MOD a *= a; a %= MOD x = x[:L] x.flags.writeable = False return x N, M, P = map(int, readline().split()) V = np.fromstring(read(), np.int64, sep=' ') fact, fact_inv = make_fact(N + M) P *= pow(100, MOD-2, MOD) Q = 1 - P P %= MOD Q %= MOD power_Q = make_power(Q, N+M) comb = fact[M-1:N+M-1] * fact_inv[0:N] % MOD * fact_inv[M-1] % MOD prob = np.empty(N+1, dtype=np.int64) prob[:N] = comb * power_Q[:N] % MOD * pow(P, M, MOD) % MOD prob[-1] = (1 - prob[:-1].sum()) % MOD V.sort() V = V[::-1] Vcum = np.empty(N+1, np.int64) Vcum[0] = 0 Vcum[1:] = V.cumsum() % MOD answer = (Vcum * prob % MOD).sum() % MOD print(answer)