結果

問題 No.1629 Sorting Integers (SUM of M)
ユーザー Nishin-0141Nishin-0141
提出日時 2022-01-28 19:46:35
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 1,154 ms / 2,000 ms
コード長 737 bytes
コンパイル時間 68 ms
コンパイル使用メモリ 10,948 KB
実行使用メモリ 23,824 KB
最終ジャッジ日時 2023-08-28 17:18:59
合計ジャッジ時間 8,140 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 15 ms
7,816 KB
testcase_01 AC 14 ms
7,772 KB
testcase_02 AC 16 ms
7,900 KB
testcase_03 AC 16 ms
7,960 KB
testcase_04 AC 469 ms
14,820 KB
testcase_05 AC 121 ms
9,640 KB
testcase_06 AC 147 ms
10,188 KB
testcase_07 AC 670 ms
17,536 KB
testcase_08 AC 504 ms
14,988 KB
testcase_09 AC 586 ms
16,264 KB
testcase_10 AC 519 ms
15,288 KB
testcase_11 AC 340 ms
12,928 KB
testcase_12 AC 533 ms
15,684 KB
testcase_13 AC 590 ms
16,424 KB
testcase_14 AC 397 ms
13,488 KB
testcase_15 AC 611 ms
16,540 KB
testcase_16 AC 590 ms
16,288 KB
testcase_17 AC 1,154 ms
23,824 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def per(n: int, r: list, mod: int):
    """同じものを含む順列の計算"""
    global fact, factinv
    num = fact[n]
    for i in r:
        if i:
            num *= factinv[i]
            num %= mod
    return num


n = int(input())
c = list(map(int, input().split()))
mod = 10**9 + 7

# n までのそれぞれの階乗計算(mod 含む)
fact = [1, 1]
factinv = [1, 1]
for i in range(2, n+1):
    fact.append(fact[-1] * i % mod)
    factinv.append(pow(fact[-1], mod - 2, mod))

cnt = 0
for i in range(9):
    check = False
    if c[i]:
        c[i] -= 1
        cnt += per(n - 1, c, mod) * (i + 1) % mod
        c[i] += 1
# print(cnt)

ans = 0
for i in range(n):
    ans += cnt * pow(10, i, mod)
    ans %= mod
print(ans)
0