結果

問題 No.1629 Sorting Integers (SUM of M)
ユーザー FromBooskaFromBooska
提出日時 2023-04-08 16:30:25
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 879 bytes
コンパイル時間 178 ms
コンパイル使用メモリ 82,424 KB
実行使用メモリ 93,440 KB
最終ジャッジ日時 2024-04-14 13:35:08
合計ジャッジ時間 4,049 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 38 ms
52,616 KB
testcase_01 AC 39 ms
52,748 KB
testcase_02 AC 38 ms
51,872 KB
testcase_03 AC 37 ms
53,076 KB
testcase_04 TLE -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

# 各数字ごとに、各桁に何回出るか考える、寄与分

N = int(input())
C = [0] + list(map(int, input().split()))
mod = 10**9+7

# nCrメモ化パッケージ
factorial = [1] #0分
inverse = [1] #0分
for i in range(1, N+1):
    factorial.append(factorial[-1]*i%mod)
    inverse.append(pow(factorial[-1], mod-2, mod))
    
def nCr_fast(N, R, MOD):
    if N < R or R < 0:
        return 0
    elif R == 0 or R == N:
        return 1
    return factorial[N]*inverse[R]*inverse[N-R]%MOD

total = 1
N_remainder = N
for i in range(1, 10):
    if C[i] > 0:
        total *= nCr_fast(N_remainder, C[i], mod)
        total %= mod
        N_remainder -= C[i]

nCr_list = [0]
for i in range(1, 10):
    calc = total*C[i]//N
    nCr_list.append(calc)

ans = 0
for d in range(N):
    for i in range(10):
        ans += i*nCr_list[i]*(10**d)
        ans %= mod
print(ans%mod)

0