結果

問題 No.1629 Sorting Integers (SUM of M)
ユーザー NatsubiSoganNatsubiSogan
提出日時 2021-07-30 20:58:10
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 175 ms / 2,000 ms
コード長 1,185 bytes
コンパイル時間 141 ms
コンパイル使用メモリ 11,020 KB
実行使用メモリ 39,704 KB
最終ジャッジ日時 2023-10-14 03:13:37
合計ジャッジ時間 2,353 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 17 ms
8,128 KB
testcase_01 AC 16 ms
8,276 KB
testcase_02 AC 17 ms
8,208 KB
testcase_03 AC 17 ms
8,268 KB
testcase_04 AC 83 ms
21,344 KB
testcase_05 AC 32 ms
11,372 KB
testcase_06 AC 38 ms
12,276 KB
testcase_07 AC 113 ms
27,032 KB
testcase_08 AC 88 ms
22,008 KB
testcase_09 AC 100 ms
24,624 KB
testcase_10 AC 89 ms
22,288 KB
testcase_11 AC 64 ms
17,756 KB
testcase_12 AC 91 ms
22,940 KB
testcase_13 AC 100 ms
24,500 KB
testcase_14 AC 74 ms
19,104 KB
testcase_15 AC 103 ms
25,052 KB
testcase_16 AC 100 ms
24,468 KB
testcase_17 AC 175 ms
39,704 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

mod = 10 ** 9 + 7
class Combinatorics:
    def __init__(self, n):
        self.n = n
        self.fa = [1] * (self.n * 2 + 1)
        self.fi = [1] * (self.n * 2 + 1)

        for i in range(1, self.n * 2 + 1):
            self.fa[i] = self.fa[i - 1] * i % mod

        self.fi[-1] = pow(self.fa[-1], mod - 2, mod)

        for i in range(self.n * 2, 0, -1):
            self.fi[i - 1] = self.fi[i] * i % mod

    def comb(self, n, r):
        if n < r:return 0
        if n < 0 or r < 0:return 0
        return self.fa[n] * self.fi[r] % mod * self.fi[n - r] % mod

    def perm(self, n, r):
        if n < r:return 0
        if n < 0 or r < 0:return 0
        return self.fa[n] * self.fi[n - r] % mod
        
    def combr(self, n, r):
        if n == r == 0:return 1
        return self.comb(n + r - 1, r)


n = int(input())
c = list(map(int, input().split()))

C = Combinatorics(n)


ans = 0
for i in range(9):
    if c[i] == 0: continue
    c[i] -= 1
    cur = n - 1
    cnt = 1
    for j in c:
        cnt *= C.comb(cur, j)
        cnt %= mod
        cur -= j
    c[i] += 1
    ans += (i + 1) * cnt
    ans %= mod
print(ans * (pow(10, n, mod) - 1) * pow(9, mod - 2, mod) % mod)

0