結果

問題 No.1102 Remnants
ユーザー simansiman
提出日時 2022-11-03 16:27:40
言語 Ruby
(3.3.0)
結果
RE  
実行時間 -
コード長 544 bytes
コンパイル時間 335 ms
コンパイル使用メモリ 11,548 KB
実行使用メモリ 41,636 KB
最終ジャッジ日時 2023-09-25 01:09:02
合計ジャッジ時間 6,726 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 82 ms
15,300 KB
testcase_01 AC 81 ms
15,252 KB
testcase_02 AC 80 ms
15,176 KB
testcase_03 AC 79 ms
15,152 KB
testcase_04 AC 81 ms
15,204 KB
testcase_05 AC 276 ms
39,944 KB
testcase_06 AC 113 ms
18,740 KB
testcase_07 RE -
testcase_08 AC 86 ms
15,300 KB
testcase_09 AC 89 ms
15,992 KB
testcase_10 AC 84 ms
15,496 KB
testcase_11 AC 106 ms
17,008 KB
testcase_12 RE -
testcase_13 AC 89 ms
16,056 KB
testcase_14 AC 183 ms
24,624 KB
testcase_15 AC 165 ms
23,600 KB
testcase_16 AC 319 ms
41,636 KB
testcase_17 RE -
testcase_18 RE -
testcase_19 RE -
testcase_20 RE -
testcase_21 RE -
testcase_22 RE -
testcase_23 RE -
testcase_24 RE -
testcase_25 RE -
testcase_26 RE -
testcase_27 RE -
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

class Integer
  def mod_inverse(mod)
    self.pow(mod - 2, mod)
  end
end

N, K = gets.split.map(&:to_i)
A = gets.split.map(&:to_i)
MOD = 10 ** 9 + 7

def comb(n, k, memo)
  return memo[n][k] if memo[n][k]

  if k == 0 || n == k
    return 1
  end

  if k == 1 || k == n - 1
    return n
  end

  memo[n][k] = (comb(n - 1, k, memo) * n * (n - k).mod_inverse(MOD)) % MOD
end

memo = Hash.new { |h, k| h[k] = {} }
ans = 0

A.each.with_index(1) do |a, i|
  ans += a * comb(K + i - 1, K, memo) * comb(N - i + K, K, memo)
  ans %= MOD
end

puts ans
0