結果

問題 No.1102 Remnants
ユーザー yuruhiyayuruhiya
提出日時 2020-07-05 11:31:33
言語 Crystal
(1.11.2)
結果
AC  
実行時間 81 ms / 2,000 ms
コード長 1,369 bytes
コンパイル時間 17,294 ms
コンパイル使用メモリ 256,436 KB
実行使用メモリ 18,228 KB
最終ジャッジ日時 2023-09-13 11:01:41
合計ジャッジ時間 19,485 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,396 KB
testcase_01 AC 2 ms
4,388 KB
testcase_02 AC 3 ms
4,380 KB
testcase_03 AC 3 ms
4,468 KB
testcase_04 AC 3 ms
4,380 KB
testcase_05 AC 62 ms
15,056 KB
testcase_06 AC 12 ms
6,160 KB
testcase_07 AC 81 ms
18,228 KB
testcase_08 AC 3 ms
4,680 KB
testcase_09 AC 5 ms
5,108 KB
testcase_10 AC 3 ms
4,500 KB
testcase_11 AC 5 ms
4,920 KB
testcase_12 AC 6 ms
5,060 KB
testcase_13 AC 6 ms
5,012 KB
testcase_14 AC 38 ms
10,624 KB
testcase_15 AC 30 ms
9,628 KB
testcase_16 AC 72 ms
16,704 KB
testcase_17 AC 72 ms
16,552 KB
testcase_18 AC 68 ms
16,928 KB
testcase_19 AC 26 ms
9,324 KB
testcase_20 AC 9 ms
5,904 KB
testcase_21 AC 42 ms
13,100 KB
testcase_22 AC 61 ms
17,688 KB
testcase_23 AC 46 ms
13,972 KB
testcase_24 AC 34 ms
10,332 KB
testcase_25 AC 70 ms
17,340 KB
testcase_26 AC 6 ms
5,264 KB
testcase_27 AC 20 ms
7,664 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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]
}
0