結果

問題 No.797 Noelちゃんとピラミッド
ユーザー simansiman
提出日時 2021-09-27 09:30:40
言語 Ruby
(3.3.0)
結果
AC  
実行時間 203 ms / 2,000 ms
コード長 881 bytes
コンパイル時間 41 ms
コンパイル使用メモリ 11,184 KB
実行使用メモリ 24,816 KB
最終ジャッジ日時 2023-09-20 08:41:57
合計ジャッジ時間 12,929 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 84 ms
15,180 KB
testcase_01 AC 87 ms
15,112 KB
testcase_02 AC 84 ms
15,164 KB
testcase_03 AC 201 ms
24,660 KB
testcase_04 AC 200 ms
24,556 KB
testcase_05 AC 199 ms
24,648 KB
testcase_06 AC 199 ms
24,704 KB
testcase_07 AC 200 ms
24,608 KB
testcase_08 AC 199 ms
24,548 KB
testcase_09 AC 198 ms
24,708 KB
testcase_10 AC 200 ms
24,556 KB
testcase_11 AC 199 ms
24,468 KB
testcase_12 AC 199 ms
24,596 KB
testcase_13 AC 198 ms
24,716 KB
testcase_14 AC 195 ms
24,536 KB
testcase_15 AC 198 ms
24,804 KB
testcase_16 AC 201 ms
24,764 KB
testcase_17 AC 200 ms
24,816 KB
testcase_18 AC 201 ms
24,536 KB
testcase_19 AC 199 ms
24,568 KB
testcase_20 AC 203 ms
24,768 KB
testcase_21 AC 200 ms
24,796 KB
testcase_22 AC 201 ms
24,704 KB
testcase_23 AC 162 ms
21,676 KB
testcase_24 AC 109 ms
17,000 KB
testcase_25 AC 151 ms
20,636 KB
testcase_26 AC 152 ms
20,436 KB
testcase_27 AC 196 ms
24,388 KB
testcase_28 AC 178 ms
23,320 KB
testcase_29 AC 99 ms
16,024 KB
testcase_30 AC 106 ms
16,904 KB
testcase_31 AC 159 ms
21,396 KB
testcase_32 AC 123 ms
17,980 KB
testcase_33 AC 150 ms
20,308 KB
testcase_34 AC 130 ms
19,172 KB
testcase_35 AC 199 ms
24,544 KB
testcase_36 AC 96 ms
15,996 KB
testcase_37 AC 177 ms
23,316 KB
testcase_38 AC 193 ms
23,960 KB
testcase_39 AC 150 ms
20,384 KB
testcase_40 AC 97 ms
15,868 KB
testcase_41 AC 101 ms
16,488 KB
testcase_42 AC 146 ms
20,288 KB
testcase_43 AC 85 ms
15,100 KB
testcase_44 AC 84 ms
15,304 KB
testcase_45 AC 85 ms
15,052 KB
testcase_46 AC 83 ms
15,164 KB
testcase_47 AC 86 ms
15,040 KB
testcase_48 AC 84 ms
15,044 KB
testcase_49 AC 85 ms
15,032 KB
testcase_50 AC 85 ms
15,096 KB
testcase_51 AC 85 ms
15,176 KB
testcase_52 AC 85 ms
15,120 KB
testcase_53 AC 85 ms
15,072 KB
testcase_54 AC 87 ms
15,160 KB
testcase_55 AC 85 ms
15,260 KB
testcase_56 AC 85 ms
15,264 KB
testcase_57 AC 85 ms
15,096 KB
testcase_58 AC 85 ms
15,044 KB
testcase_59 AC 86 ms
15,204 KB
testcase_60 AC 85 ms
15,108 KB
testcase_61 AC 83 ms
14,964 KB
testcase_62 AC 84 ms
15,032 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

class ModInteger
  attr_reader :fac, :inv, :finv, :mod

  MOD = 10 ** 9 + 7

  def initialize(n, mod: MOD)
    @mod = mod
    @fac = [1, 1]
    @inv = [1, 1]
    @finv = [1, 1]

    (2..n).each do |i|
      @fac[i] = fac[i - 1] * i % mod
      @inv[i] = mod - inv[mod % i] * (mod / i) % mod
      @finv[i] = finv[i - 1] * inv[i] % mod
    end
  end

  def combination(n, k)
    return 0 if n < k
    return 0 if n < 0 || k < 0

    fac[n] * (finv[k] * finv[n - k] % mod) % mod
  end

  def permutation(n, k = n)
    return 0 if n < k
    return 0 if n < 0 || k < 0

    fac[n] * (finv[n - k] % mod) % mod
  end

  def repeated_combination(n, k)
    combination(n + k - 1, k)
  end
end

MOD = 10 ** 9 + 7
N = gets.to_i
A = gets.split.map(&:to_i)
mi = ModInteger.new(N, mod: MOD)

ans = 0

A.each_with_index do |a, i|
  ans += a * mi.combination(N - 1, i)
  ans %= MOD
end

puts ans
0