結果

問題 No.1629 Sorting Integers (SUM of M)
ユーザー FromBooskaFromBooska
提出日時 2023-06-01 18:18:17
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 241 ms / 2,000 ms
コード長 1,154 bytes
コンパイル時間 348 ms
コンパイル使用メモリ 87,256 KB
実行使用メモリ 103,768 KB
最終ジャッジ日時 2023-08-28 02:05:48
合計ジャッジ時間 4,140 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 80 ms
71,596 KB
testcase_01 AC 80 ms
71,428 KB
testcase_02 AC 78 ms
71,392 KB
testcase_03 AC 80 ms
71,380 KB
testcase_04 AC 152 ms
86,972 KB
testcase_05 AC 96 ms
76,896 KB
testcase_06 AC 102 ms
77,708 KB
testcase_07 AC 179 ms
92,452 KB
testcase_08 AC 150 ms
87,196 KB
testcase_09 AC 162 ms
88,868 KB
testcase_10 AC 152 ms
87,184 KB
testcase_11 AC 131 ms
83,224 KB
testcase_12 AC 157 ms
88,996 KB
testcase_13 AC 162 ms
88,720 KB
testcase_14 AC 135 ms
84,372 KB
testcase_15 AC 167 ms
90,496 KB
testcase_16 AC 161 ms
88,820 KB
testcase_17 AC 241 ms
103,768 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

# たとえばC = 432000000, N=9とすると
# 数字の全組合せのパターン数は9!/(4!3!2!)
# では100の位に2が来るパターン数は、1つ数字が固定されるので8!/(4!(3-1)!2!)
# つまり寄与数で考えれば2*100*8!/(4!(3-1)!2!)
# 求めたいのはΣ(桁d from 0 to N-1)Σ(i from 1 to 9) i*10**d*(以下)
# ci*(N-1)!/(c1!c2!---c9!)
# Σ内を変数で分けて
# = (N-1)! Σ(桁d from 0 to N-1)10**d Σ(i from 1 to 9) i*ci/(c1!c2!---c9!)
# = (N-1)! (10**N - 1)/9 Σ(i from 1 to 9) i*ci/(c1!c2!---c9!)
# = calc1 * calc2 * calc3とする

N = int(input())
C = 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))

calc1 = factorial[N-1]
calc2 = (pow(10, N, mod)-1)*pow(9, mod-2, mod)
#print(calc1)
#print(calc2)

inv = 1
for c in C:
    inv *= factorial[c]
    inv %= mod
c_factorial = pow(inv, mod-2, mod)
calc3 = 0
for i in range(1, 10):
    calc3 += i*C[i-1]*c_factorial
    calc3 %= mod
ans = calc1 * calc2 * calc3 
ans %= mod
print(ans)
0