結果
問題 |
No.1629 Sorting Integers (SUM of M)
|
ユーザー |
![]() |
提出日時 | 2021-08-01 07:21:07 |
言語 | Ruby (3.4.1) |
結果 |
WA
|
実行時間 | - |
コード長 | 707 bytes |
コンパイル時間 | 258 ms |
コンパイル使用メモリ | 7,680 KB |
実行使用メモリ | 19,612 KB |
最終ジャッジ日時 | 2024-09-16 12:43:35 |
合計ジャッジ時間 | 16,245 ms |
ジャッジサーバーID (参考情報) |
judge6 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | WA * 13 TLE * 1 |
コンパイルメッセージ
Syntax OK
ソースコード
class Integer def mod_pow(n, mod) x = self res = 1 while n > 0 res = res * x % mod if n[0] == 1 x = x * x % mod n >>= 1 end res end def mod_inverse(mod) mod_pow(mod - 2, mod) end end N = gets.to_i C = gets.split.map(&:to_i) S = C.sum MOD = 10 ** 9 + 7 mod = Array.new(10, 0) b = 1 2.upto(S - 1) do |x| b *= x b %= MOD end 1.upto(9) do |i| m = b 1.upto(9) do |j| next if i == j next if C[j - 1] == 0 m *= C[j - 1].mod_inverse(MOD) end mod[i] = m end ans = 0 base = 1 N.times do C.each.with_index(1) do |c, i| next if c == 0 ans += mod[i] * base * i ans %= MOD end base *= 10 base %= MOD end puts ans