結果

問題 No.1102 Remnants
ユーザー yuruhiyayuruhiya
提出日時 2020-07-05 11:28:40
言語 Crystal
(1.11.2)
結果
AC  
実行時間 113 ms / 2,000 ms
コード長 1,383 bytes
コンパイル時間 18,226 ms
コンパイル使用メモリ 256,164 KB
実行使用メモリ 25,284 KB
最終ジャッジ日時 2023-09-13 11:01:18
合計ジャッジ時間 20,820 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,404 KB
testcase_01 AC 2 ms
4,420 KB
testcase_02 AC 3 ms
4,412 KB
testcase_03 AC 2 ms
4,404 KB
testcase_04 AC 2 ms
4,388 KB
testcase_05 AC 94 ms
23,692 KB
testcase_06 AC 15 ms
6,808 KB
testcase_07 AC 113 ms
24,848 KB
testcase_08 AC 4 ms
4,808 KB
testcase_09 AC 6 ms
5,404 KB
testcase_10 AC 3 ms
4,736 KB
testcase_11 AC 5 ms
5,080 KB
testcase_12 AC 7 ms
5,432 KB
testcase_13 AC 6 ms
5,484 KB
testcase_14 AC 52 ms
15,092 KB
testcase_15 AC 39 ms
12,456 KB
testcase_16 AC 107 ms
22,432 KB
testcase_17 AC 102 ms
25,284 KB
testcase_18 AC 98 ms
22,548 KB
testcase_19 AC 33 ms
11,584 KB
testcase_20 AC 11 ms
6,560 KB
testcase_21 AC 56 ms
15,264 KB
testcase_22 AC 84 ms
22,900 KB
testcase_23 AC 63 ms
16,548 KB
testcase_24 AC 46 ms
14,464 KB
testcase_25 AC 100 ms
23,780 KB
testcase_26 AC 7 ms
5,564 KB
testcase_27 AC 25 ms
8,996 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 = Hash(Int32, ModInt).new
comb[k] = ModInt.new(1)
(k + 1..k + n).each do |i|
  comb[i] = comb[i - 1] / (i - k) * i
end

puts a.each_with_index.sum(ModInt.zero) { |v, i|
  v * comb[i + k]*comb[n - i - 1 + k]
}
0