結果
問題 | No.766 金魚すくい |
ユーザー | maspy |
提出日時 | 2020-02-04 09:45:11 |
言語 | Python3 (3.12.2 + numpy 1.26.4 + scipy 1.12.0) |
結果 |
AC
|
実行時間 | 620 ms / 1,500 ms |
コード長 | 1,555 bytes |
コンパイル時間 | 209 ms |
コンパイル使用メモリ | 12,928 KB |
実行使用メモリ | 54,924 KB |
最終ジャッジ日時 | 2024-09-19 20:29:53 |
合計ジャッジ時間 | 26,050 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 500 ms
43,936 KB |
testcase_01 | AC | 481 ms
44,192 KB |
testcase_02 | AC | 489 ms
44,328 KB |
testcase_03 | AC | 483 ms
44,184 KB |
testcase_04 | AC | 465 ms
44,068 KB |
testcase_05 | AC | 468 ms
44,708 KB |
testcase_06 | AC | 466 ms
44,232 KB |
testcase_07 | AC | 480 ms
44,188 KB |
testcase_08 | AC | 482 ms
44,248 KB |
testcase_09 | AC | 469 ms
44,584 KB |
testcase_10 | AC | 474 ms
44,320 KB |
testcase_11 | AC | 469 ms
44,072 KB |
testcase_12 | AC | 472 ms
44,068 KB |
testcase_13 | AC | 480 ms
43,936 KB |
testcase_14 | AC | 473 ms
44,704 KB |
testcase_15 | AC | 469 ms
44,452 KB |
testcase_16 | AC | 481 ms
44,580 KB |
testcase_17 | AC | 471 ms
44,068 KB |
testcase_18 | AC | 473 ms
44,320 KB |
testcase_19 | AC | 479 ms
43,940 KB |
testcase_20 | AC | 486 ms
44,580 KB |
testcase_21 | AC | 484 ms
44,192 KB |
testcase_22 | AC | 491 ms
44,580 KB |
testcase_23 | AC | 620 ms
54,408 KB |
testcase_24 | AC | 525 ms
54,736 KB |
testcase_25 | AC | 523 ms
54,924 KB |
testcase_26 | AC | 519 ms
54,276 KB |
testcase_27 | AC | 515 ms
54,604 KB |
testcase_28 | AC | 515 ms
54,596 KB |
testcase_29 | AC | 518 ms
54,440 KB |
testcase_30 | AC | 515 ms
54,448 KB |
testcase_31 | AC | 511 ms
54,492 KB |
testcase_32 | AC | 525 ms
54,492 KB |
testcase_33 | AC | 500 ms
51,024 KB |
testcase_34 | AC | 506 ms
51,152 KB |
testcase_35 | AC | 488 ms
46,448 KB |
testcase_36 | AC | 485 ms
47,004 KB |
testcase_37 | AC | 529 ms
54,436 KB |
testcase_38 | AC | 535 ms
54,900 KB |
testcase_39 | AC | 539 ms
54,324 KB |
testcase_40 | AC | 517 ms
54,372 KB |
testcase_41 | AC | 527 ms
54,920 KB |
testcase_42 | AC | 523 ms
54,816 KB |
testcase_43 | AC | 473 ms
44,192 KB |
testcase_44 | AC | 478 ms
44,444 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)