結果
| 問題 | No.1102 Remnants | 
| コンテスト | |
| ユーザー |  yuruhiya | 
| 提出日時 | 2020-07-05 11:31:33 | 
| 言語 | Crystal (1.14.0) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 78 ms / 2,000 ms | 
| コード長 | 1,369 bytes | 
| コンパイル時間 | 11,806 ms | 
| コンパイル使用メモリ | 296,784 KB | 
| 実行使用メモリ | 19,240 KB | 
| 最終ジャッジ日時 | 2024-06-30 20:27:49 | 
| 合計ジャッジ時間 | 13,449 ms | 
| ジャッジサーバーID (参考情報) | judge2 / judge5 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 3 | 
| other | AC * 25 | 
ソースコード
struct ModInt
  @@MOD = 1_000_000_007i64
  def self.mod
    @@MOD
  end
  def self.zero
    ModInt.new(0)
  end
  def initialize(n)
    @n = n.to_i64 % @@MOD
  end
  getter n : Int64
  def + : self
    self
  end
  def - : self
    ModInt.new(n != 0 ? @@MOD - @n : 0)
  end
  def +(m)
    ModInt.new(@n + m.to_i64 % @@MOD)
  end
  def -(m)
    ModInt.new(@n - m.to_i64 % @@MOD)
  end
  def *(m)
    ModInt.new(@n * m.to_i64 % @@MOD)
  end
  def /(m)
    raise DivisionByZeroError.new if m == 0
    a, b, u, v = m.to_i64, @@MOD, 1i64, 0i64
    while b != 0
      t = a // b
      a -= t * b
      a, b = b, a
      u -= t * v
      u, v = v, u
    end
    ModInt.new(@n * u)
  end
  def //(m)
    self / m
  end
  def **(m)
    t, res = self, ModInt.new(1)
    while m > 0
      res *= t if m.odd?
      t *= t
      m >>= 1
    end
    res
  end
  def ==(m)
    @n == m.to_i64
  end
  def !=(m)
    @n != m.to_i64
  end
  def succ
    self + 1
  end
  def pred
    self - 1
  end
  def to_i64 : Int64
    @n
  end
  delegate to_s, to: @n
  delegate inspect, to: @n
end
n, k = read_line.split.map &.to_i
a = read_line.split.map { |i| ModInt.new(i) }
comb = [ModInt.zero] * (n + 1)
comb[0] = ModInt.new(1)
(1..n).each do |i|
  comb[i] = comb[i - 1] / i * (i + k)
end
puts a.each_with_index.sum(ModInt.zero) { |v, i|
  v * comb[i] * comb[n - i - 1]
}
            
            
            
        