結果

問題 No.829 成長関数インフレ中
ユーザー maspymaspy
提出日時 2020-05-03 17:51:45
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 436 ms / 2,000 ms
コード長 712 bytes
コンパイル時間 326 ms
コンパイル使用メモリ 10,828 KB
実行使用メモリ 25,064 KB
最終ジャッジ日時 2023-09-03 21:08:56
合計ジャッジ時間 4,209 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 15 ms
7,860 KB
testcase_01 AC 15 ms
7,668 KB
testcase_02 AC 15 ms
7,720 KB
testcase_03 AC 15 ms
7,800 KB
testcase_04 AC 15 ms
7,876 KB
testcase_05 AC 15 ms
7,912 KB
testcase_06 AC 15 ms
7,664 KB
testcase_07 AC 15 ms
7,816 KB
testcase_08 AC 15 ms
7,744 KB
testcase_09 AC 17 ms
7,752 KB
testcase_10 AC 15 ms
7,744 KB
testcase_11 AC 15 ms
7,812 KB
testcase_12 AC 255 ms
19,648 KB
testcase_13 AC 31 ms
8,828 KB
testcase_14 AC 178 ms
15,956 KB
testcase_15 AC 136 ms
14,576 KB
testcase_16 AC 257 ms
18,864 KB
testcase_17 AC 421 ms
25,064 KB
testcase_18 AC 409 ms
21,804 KB
testcase_19 AC 368 ms
21,036 KB
testcase_20 AC 436 ms
23,168 KB
testcase_21 AC 151 ms
14,812 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

MOD = 10**9 + 7

N, B, *S = map(int, read().split())

counter = [0] * N
for x in S:
    counter[x] += 1

powB = [1] * N
for n in range(1, N):
    powB[n] = powB[n - 1] * B % MOD

used = 0
f = 1
df = 0
for n in counter[::-1]:
    if not n:
        continue
    total = 1
    stay = 1
    for i in range(1, n + 1):
        total *= used + i
        stay *= used + i - 1
        total %= MOD
        stay %= MOD
    a = stay
    b = total - stay
    # a + bx をかける
    g = a + b * B
    dg = b
    f, df = f * g, f * dg + df * g
    f %= MOD
    df %= MOD
    used += n

print(df * B % MOD)
0