結果
| 問題 |
No.829 成長関数インフレ中
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2018-12-07 00:52:15 |
| 言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
| 結果 |
AC
|
| 実行時間 | 1,929 ms / 2,000 ms |
| コード長 | 1,698 bytes |
| コンパイル時間 | 82 ms |
| コンパイル使用メモリ | 12,672 KB |
| 実行使用メモリ | 34,648 KB |
| 最終ジャッジ日時 | 2024-09-15 13:20:46 |
| 合計ジャッジ時間 | 10,355 ms |
|
ジャッジサーバーID (参考情報) |
judge6 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 22 |
コンパイルメッセージ
Main.py:18: SyntaxWarning: "is not" with 'int' literal. Did you mean "!="? while index is not 0: Main.py:18: SyntaxWarning: "is not" with 'int' literal. Did you mean "!="? while index is not 0:
ソースコード
import sys
def prod(a, b):
return 0 if a < b else fac[a] * finv[a-b] % 1000000007
def mod_inverse(a):
# r, w = [1, a], [0, 1000000007]
# while w[1] is not 1:
# q = (r[1] // w[1])
# nw = [r[0]-q*w[0], r[1]-q*w[1]]
# r = w
# w = nw
# return (1000000007 + w[0] % 1000000007) % 1000000007
index = 1000000005
res, nw = 1, a
while index is not 0:
if index % 2 == 1:
res = res * nw % 1000000007
nw = nw * nw % 1000000007
index >>= 1
return res
if __name__ == '__main__':
n, B = map(int, sys.stdin.readline().split())
cnt, inv, fac, finv = [0]*(n+1), [0]*(n+1), [0]*(n+1), [0]*(n+1)
for val in list(map(int, sys.stdin.readline().split())):
cnt[val] += 1
fac[0] = fac[1] = 1
finv[0] = finv[1] = 1
inv[1] = 1
for i in range(2, n):
inv[i] = 1000000007 - inv[1000000007 % i] * (1000000007 // i) % 1000000007
fac[i] = fac[i - 1] * i % 1000000007
finv[i] = finv[i - 1] * inv[i] % 1000000007
id, ad, ans, s, t, pl = 0, 0, B, 0, 0, B
flag = False
for i in range(n-1, -1, -1):
if cnt[i] == 0:
continue
s = prod(id + cnt[i] - 1, cnt[i] - 1) * cnt[i] % 1000000007
t = (s * B + prod(id + cnt[i] - 1, cnt[i])) % 1000000007
if t > 0:
ad = (ad + s * mod_inverse(t) % 1000000007) % 1000000007
pl = pl * t % 1000000007
else:
if flag:
pl = 0
else:
flag = True
pl = pl * s % 1000000007
ans = ans * t % 1000000007
id += cnt[i]
print((ans * ad + (pl if flag else 0)) % 1000000007)