結果

問題 No.1111 コード進行
ユーザー yuruhiyayuruhiya
提出日時 2020-07-11 18:03:26
言語 Crystal
(1.11.2)
結果
RE  
実行時間 -
コード長 1,639 bytes
コンパイル時間 18,564 ms
コンパイル使用メモリ 257,168 KB
実行使用メモリ 4,788 KB
最終ジャッジ日時 2023-09-13 11:08:38
合計ジャッジ時間 19,994 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
4,492 KB
testcase_01 AC 3 ms
4,396 KB
testcase_02 AC 2 ms
4,496 KB
testcase_03 RE -
testcase_04 AC 2 ms
4,396 KB
testcase_05 RE -
testcase_06 RE -
testcase_07 RE -
testcase_08 RE -
testcase_09 RE -
testcase_10 RE -
testcase_11 RE -
testcase_12 RE -
testcase_13 RE -
testcase_14 RE -
testcase_15 RE -
testcase_16 RE -
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 -
testcase_28 RE -
testcase_29 RE -
testcase_30 RE -
testcase_31 RE -
testcase_32 RE -
testcase_33 RE -
testcase_34 RE -
testcase_35 RE -
testcase_36 RE -
testcase_37 RE -
testcase_38 RE -
testcase_39 RE -
testcase_40 RE -
testcase_41 RE -
testcase_42 RE -
testcase_43 RE -
testcase_44 RE -
testcase_45 RE -
testcase_46 RE -
testcase_47 RE -
testcase_48 RE -
testcase_49 RE -
権限があれば一括ダウンロードができます
コンパイルメッセージ
In Main.cr:102:6

 102 | ii.product(jj) do |from, sum|
          ^------
Warning: Deprecated Array(Int32)#product. Use `Indexable#each_cartesian(*others : Indexable, &block)` instead

A total of 1 warnings were found.

ソースコード

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, m, k = read_line.split.map &.to_i
MAX_CODE = 3
code = Array.new(MAX_CODE) { [] of Tuple(Int32, Int32) }
m.times do
  p, q, c = read_line.split.map &.to_i
  code[p - 1] << {q - 1, c}
end

dp = (1..MAX_CODE).map { [ModInt.new(1)] + [ModInt.zero] * k }
n.pred.times do
  dp2 = (0...MAX_CODE).map { [ModInt.zero] * (k + 1) }
  ii = (0...MAX_CODE).to_a
  jj = (0..k).to_a
  ii.product(jj) do |from, sum|
    code[from].each do |to, cost|
      dp2[to][sum + cost] += dp[from][sum] if sum + cost <= k
    end
  end
	dp = dp2
end
puts dp.sum { |a| a[k] }
0