結果

問題 No.1629 Sorting Integers (SUM of M)
ユーザー simansiman
提出日時 2021-08-01 07:21:07
言語 Ruby
(3.3.0)
結果
WA  
実行時間 -
コード長 707 bytes
コンパイル時間 944 ms
コンパイル使用メモリ 11,248 KB
実行使用メモリ 22,028 KB
最終ジャッジ日時 2023-10-14 18:41:31
合計ジャッジ時間 16,639 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 77 ms
22,028 KB
testcase_01 AC 75 ms
15,228 KB
testcase_02 AC 74 ms
15,152 KB
testcase_03 AC 75 ms
15,240 KB
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 TLE -
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

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
0