結果

問題 No.1629 Sorting Integers (SUM of M)
ユーザー 👑 SPD_9X2SPD_9X2
提出日時 2021-07-30 20:58:11
言語 PyPy3
(7.3.13)
結果
AC  
実行時間 188 ms / 2,000 ms
コード長 1,022 bytes
コンパイル時間 1,399 ms
コンパイル使用メモリ 86,448 KB
実行使用メモリ 98,692 KB
最終ジャッジ日時 2023-10-14 03:13:43
合計ジャッジ時間 4,798 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 104 ms
97,948 KB
testcase_01 AC 109 ms
98,104 KB
testcase_02 AC 106 ms
98,068 KB
testcase_03 AC 106 ms
98,108 KB
testcase_04 AC 137 ms
98,244 KB
testcase_05 AC 113 ms
98,492 KB
testcase_06 AC 118 ms
98,492 KB
testcase_07 AC 154 ms
98,488 KB
testcase_08 AC 144 ms
98,232 KB
testcase_09 AC 148 ms
98,568 KB
testcase_10 AC 142 ms
98,384 KB
testcase_11 AC 132 ms
98,484 KB
testcase_12 AC 148 ms
98,380 KB
testcase_13 AC 150 ms
98,632 KB
testcase_14 AC 133 ms
98,372 KB
testcase_15 AC 149 ms
98,628 KB
testcase_16 AC 148 ms
98,692 KB
testcase_17 AC 188 ms
98,232 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

"""

"""

import sys
from sys import stdin

def modfac(n, MOD):
 
    f = 1
    factorials = [1]
    for m in range(1, n + 1):
        f *= m
        f %= MOD
        factorials.append(f)
    inv = pow(f, MOD - 2, MOD)
    invs = [1] * (n + 1)
    invs[n] = inv
    for m in range(n, 1, -1):
        inv *= m
        inv %= MOD
        invs[m - 1] = inv
    return factorials, invs


def modnCr(n,r): #上で求めたfacとinvsを引数に入れるべし(上の関数で与えたnが計算できる最大のnになる)

    return fac[n] * inv[n-r] * inv[r] % mod

mod = 10**9+7
fac,inv = modfac(300000,mod)

N = int(stdin.readline())
c = list(map(int,stdin.readline().split()))

ans = 0
ds = 0
for i in range(N):
    ds += pow(10,i,mod)
    ds %= mod

for i in range(9):
    v = i+1

    if c[i] != 0:
        now = modnCr(N-1,c[i]-1)
        rem = N-c[i]
        for j in range(9):
            if j != i:
                now *= modnCr(rem,c[j])
                rem -= c[j]
        ans += now * ds * v

print (ans % mod)
0