結果

問題 No.829 成長関数インフレ中
ユーザー koprickykopricky
提出日時 2018-12-07 00:58:08
言語 Python3
(3.11.6 + numpy 1.26.0 + scipy 1.11.3)
結果
AC  
実行時間 1,491 ms / 2,000 ms
コード長 1,333 bytes
コンパイル時間 144 ms
コンパイル使用メモリ 10,736 KB
実行使用メモリ 33,632 KB
最終ジャッジ日時 2023-10-13 17:26:51
合計ジャッジ時間 8,365 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 17 ms
8,012 KB
testcase_01 AC 16 ms
8,024 KB
testcase_02 AC 16 ms
8,140 KB
testcase_03 AC 16 ms
8,040 KB
testcase_04 AC 17 ms
8,088 KB
testcase_05 AC 17 ms
8,040 KB
testcase_06 AC 17 ms
8,032 KB
testcase_07 AC 17 ms
8,044 KB
testcase_08 AC 16 ms
8,068 KB
testcase_09 AC 16 ms
8,056 KB
testcase_10 AC 17 ms
8,064 KB
testcase_11 AC 16 ms
8,072 KB
testcase_12 AC 353 ms
31,864 KB
testcase_13 AC 37 ms
9,972 KB
testcase_14 AC 243 ms
24,452 KB
testcase_15 AC 344 ms
16,040 KB
testcase_16 AC 659 ms
24,016 KB
testcase_17 AC 1,182 ms
33,632 KB
testcase_18 AC 1,213 ms
28,984 KB
testcase_19 AC 1,181 ms
27,320 KB
testcase_20 AC 1,491 ms
30,880 KB
testcase_21 AC 200 ms
22,288 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Main.py:12: SyntaxWarning: "is not" with a literal. Did you mean "!="?
  while w[1] is not 1:
Main.py:12: SyntaxWarning: "is not" with a literal. Did you mean "!="?
  while w[1] is not 1:

ソースコード

diff #

import sys

MOD = 1000000007


def prod(a, b):
    return 0 if a < b else fac[a] * finv[a-b]


def mod_inverse(a):
    r, w = [1, a], [0, MOD]
    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 (MOD + w[0] % MOD) % MOD


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] = MOD - inv[MOD % i] * (MOD // i) % MOD
        fac[i] = fac[i - 1] * i % MOD
        finv[i] = finv[i - 1] * inv[i] % MOD
    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]
        t = (s * B + prod(id + cnt[i] - 1, cnt[i])) % MOD
        if t > 0:
            ad += s * mod_inverse(t)
            pl = pl * t % MOD
        else:
            if flag:
                pl = 0
            else:
                flag = True
                pl = pl * s % MOD
        ans = ans * t % MOD
        id += cnt[i]
    print((ans * ad + (pl if flag else 0)) % MOD)
0