結果

問題 No.1629 Sorting Integers (SUM of M)
ユーザー ygd.ygd.
提出日時 2021-07-30 20:46:01
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 103 ms / 2,000 ms
コード長 1,274 bytes
コンパイル時間 288 ms
コンパイル使用メモリ 86,984 KB
実行使用メモリ 81,232 KB
最終ジャッジ日時 2023-10-14 03:03:07
合計ジャッジ時間 2,987 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 95 ms
80,992 KB
testcase_01 AC 91 ms
81,028 KB
testcase_02 AC 90 ms
81,024 KB
testcase_03 AC 90 ms
81,072 KB
testcase_04 AC 93 ms
81,144 KB
testcase_05 AC 92 ms
81,140 KB
testcase_06 AC 92 ms
81,052 KB
testcase_07 AC 96 ms
81,188 KB
testcase_08 AC 94 ms
81,148 KB
testcase_09 AC 95 ms
81,140 KB
testcase_10 AC 96 ms
81,072 KB
testcase_11 AC 96 ms
81,020 KB
testcase_12 AC 98 ms
81,168 KB
testcase_13 AC 99 ms
80,932 KB
testcase_14 AC 96 ms
80,928 KB
testcase_15 AC 96 ms
81,156 KB
testcase_16 AC 97 ms
81,232 KB
testcase_17 AC 103 ms
80,824 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def cmb(n, r, p):
  if (r < 0) or (n < r):
    return 0
  r = min(r, n - r)
  return fac[n]*finv[r]*finv[n-r]%p

def perm(n,r,p):
  if (r < 0) or (n < r):
    return 0
  return fac[n]*finv[n-r]%p

NN = 220000
MOD = pow(10,9) + 7

fac = [-1]*(NN+1); fac[0] = 1; fac[1] = 1 #階乗
finv = [-1]*(NN+1); finv[0] = 1; finv[1] = 1 #階乗の逆元
inv = [-1]*(NN+1); inv[0] = 0; inv[1] = 1 #逆元
for i in range(2,NN+1):
  fac[i] = fac[i-1]*i%MOD
  inv[i] = MOD - inv[MOD%i]*(MOD//i)%MOD
  finv[i] = finv[i-1]*inv[i]%MOD


def main():
    N = int(input())
    C = list(map(int,input().split()))
    ans = 0
    for i in range(9):
        if C[i] == 0: continue
        val = 0
        base = 1
        for j in range(N):
            val += base*(i+1)
            val %= MOD
            base *= 10
            base %= MOD
        pattern = fac[N-1]
        #print(pattern)
        for j in range(9):
            if i == j:
                num = C[j] - 1
            else:
                num = C[j]
            if C[i] == 0: continue
            #print(num,finv[num])
            pattern *= finv[num]
            pattern %= MOD
        #print(val,pattern)
        temp = val*pattern%MOD
        ans += temp
        ans %= MOD
    print(ans)


if __name__ == '__main__':
    main()
0