結果

問題 No.1629 Sorting Integers (SUM of M)
コンテスト
ユーザー norioc
提出日時 2026-05-27 19:51:00
言語 PyPy3
(7.3.17)
コンパイル:
pypy3 -mpy_compile _filename_
実行:
pypy3 _filename_
結果
AC  
実行時間 183 ms / 2,000 ms
コード長 1,137 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 378 ms
コンパイル使用メモリ 85,120 KB
実行使用メモリ 84,480 KB
最終ジャッジ日時 2026-05-27 19:51:03
合計ジャッジ時間 2,708 ms
ジャッジサーバーID
(参考情報)
judge2_0 / judge1_0
純コード判定待ち
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 14
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

class ModComb:
    def __init__(self, n: int, mod: int):
        fact = [0] * (n+1)
        fact[0] = 1
        for i in range(1, n+1):
            fact[i] = i * fact[i-1] % mod

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

    def __call__(self, n: int, k: int) -> int:
        if n < 0 or k > n: return 0
        return (self.fact[n] * self.ifact[k] % self.mod) * self.ifact[n-k] % self.mod


MOD = 10**9 + 7
N = int(input())
C = list(map(int, input().split()))

ds = [0] + C
mcomb = ModComb(N, MOD)

ans = 0
for i in range(N):
    p = pow(10, i, MOD)
    for di in range(1, 10):
        if ds[di] == 0: continue

        nume = mcomb.fact[N-1]
        deno = 1
        for dj in range(1, 10):
            if ds[dj] == 0: continue

            x = ds[dj]
            if di == dj:
                x -= 1
            deno *= mcomb.ifact[x]
            deno %= MOD

        cnt = nume * deno % MOD
        ans += di * p * cnt
        ans %= MOD

print(ans)
0