結果
問題 | No.125 悪の花弁 |
ユーザー | maspy |
提出日時 | 2020-03-28 01:32:21 |
言語 | Python3 (3.12.2 + numpy 1.26.4 + scipy 1.12.0) |
結果 |
AC
|
実行時間 | 272 ms / 5,000 ms |
コード長 | 1,418 bytes |
コンパイル時間 | 316 ms |
コンパイル使用メモリ | 10,796 KB |
実行使用メモリ | 70,744 KB |
最終ジャッジ日時 | 2023-08-30 17:14:57 |
合計ジャッジ時間 | 4,892 ms |
ジャッジサーバーID (参考情報) |
judge14 / judge13 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 215 ms
57,996 KB |
testcase_01 | AC | 222 ms
59,596 KB |
testcase_02 | AC | 259 ms
70,320 KB |
testcase_03 | AC | 272 ms
70,744 KB |
testcase_04 | AC | 238 ms
68,988 KB |
testcase_05 | AC | 236 ms
69,084 KB |
ソースコード
#!/usr/bin/ python3.8 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 K = int(readline()) C = np.array(read().split(), np.int64) N = C.sum() D = np.gcd.reduce(C) x = np.arange(1, 1100) div = x[D % x == 0] div = np.union1d(div, D // div) fact, fact_inv = make_fact(N + 1) def f(d): num = fact[N // d] den = cumprod(fact_inv[C // d])[-1] return num * den % MOD dp = {d: f(d) for d in div} keys = sorted(div, reverse=True) for d in keys: x = dp[d] for e in keys: if e <= d or e % d != 0: continue x -= dp[e] dp[d] = x answer = sum(k * v for k, v in dp.items()) % MOD answer *= pow(int(N), MOD - 2, MOD) answer %= MOD print(answer)