結果

問題 No.1629 Sorting Integers (SUM of M)
ユーザー 👑 rin204rin204
提出日時 2021-07-30 20:39:07
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 90 ms / 2,000 ms
コード長 814 bytes
コンパイル時間 347 ms
コンパイル使用メモリ 86,924 KB
実行使用メモリ 79,220 KB
最終ジャッジ日時 2023-10-14 02:52:53
合計ジャッジ時間 2,891 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 85 ms
78,940 KB
testcase_01 AC 85 ms
78,912 KB
testcase_02 AC 87 ms
78,904 KB
testcase_03 AC 89 ms
79,204 KB
testcase_04 AC 90 ms
78,832 KB
testcase_05 AC 87 ms
78,976 KB
testcase_06 AC 86 ms
78,880 KB
testcase_07 AC 86 ms
79,064 KB
testcase_08 AC 85 ms
79,204 KB
testcase_09 AC 89 ms
79,080 KB
testcase_10 AC 87 ms
79,060 KB
testcase_11 AC 85 ms
79,044 KB
testcase_12 AC 84 ms
79,000 KB
testcase_13 AC 85 ms
78,992 KB
testcase_14 AC 87 ms
79,120 KB
testcase_15 AC 88 ms
79,220 KB
testcase_16 AC 90 ms
78,760 KB
testcase_17 AC 88 ms
78,856 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

MOD = 10 ** 9 + 7
N = 200200
fact = [0 for _ in range(N)]
invfact = [0 for _ in range(N)]
fact[0] = 1
for i in range(1, N):
    fact[i] = fact[i - 1] * i % MOD

invfact[N - 1] = pow(fact[N - 1], MOD - 2, MOD)

for i in range(N - 2, -1, -1):
    invfact[i] = invfact[i + 1] * (i + 1) % MOD

def nCk(n, k):
    if k < 0 or n < k:
        return 0
    else:
        return (fact[n] * invfact[k] % MOD) * invfact[n - k] % MOD

def nHk(n, k):
    return nCk(n + k - 1, k)


n = int(input())
cnt = list(map(int, input().split()))
m = n
times = 1
for c in cnt:
    times *= nCk(m, c)
    m -= c
    times %= MOD
    
tot = 0
for i, c in enumerate(cnt, 1):
    tot += i * (times * pow(nCk(n, c), MOD - 2, MOD) * nCk(n - 1, c - 1))
    tot %= MOD

print(tot * (pow(10, n, MOD) - 1) * pow(9, MOD - 2, MOD) % MOD)
    
    

0