結果

問題 No.1111 コード進行
ユーザー yuruhiyayuruhiya
提出日時 2020-07-11 18:04:16
言語 Crystal
(1.11.2)
結果
AC  
実行時間 369 ms / 2,000 ms
コード長 1,641 bytes
コンパイル時間 17,262 ms
コンパイル使用メモリ 256,028 KB
実行使用メモリ 9,156 KB
最終ジャッジ日時 2023-09-13 11:10:11
合計ジャッジ時間 20,745 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
4,724 KB
testcase_01 AC 3 ms
4,688 KB
testcase_02 AC 2 ms
4,572 KB
testcase_03 AC 2 ms
4,608 KB
testcase_04 AC 3 ms
4,572 KB
testcase_05 AC 7 ms
8,408 KB
testcase_06 AC 6 ms
5,900 KB
testcase_07 AC 6 ms
5,824 KB
testcase_08 AC 4 ms
5,448 KB
testcase_09 AC 5 ms
5,800 KB
testcase_10 AC 7 ms
6,284 KB
testcase_11 AC 4 ms
5,364 KB
testcase_12 AC 8 ms
5,816 KB
testcase_13 AC 5 ms
5,760 KB
testcase_14 AC 10 ms
5,888 KB
testcase_15 AC 4 ms
5,224 KB
testcase_16 AC 9 ms
7,112 KB
testcase_17 AC 8 ms
6,324 KB
testcase_18 AC 4 ms
5,152 KB
testcase_19 AC 5 ms
5,936 KB
testcase_20 AC 5 ms
5,736 KB
testcase_21 AC 3 ms
4,948 KB
testcase_22 AC 9 ms
5,740 KB
testcase_23 AC 6 ms
5,812 KB
testcase_24 AC 7 ms
5,816 KB
testcase_25 AC 12 ms
5,880 KB
testcase_26 AC 9 ms
5,824 KB
testcase_27 AC 4 ms
5,520 KB
testcase_28 AC 61 ms
5,892 KB
testcase_29 AC 34 ms
5,872 KB
testcase_30 AC 55 ms
5,924 KB
testcase_31 AC 11 ms
5,928 KB
testcase_32 AC 74 ms
5,876 KB
testcase_33 AC 65 ms
5,892 KB
testcase_34 AC 48 ms
5,752 KB
testcase_35 AC 57 ms
6,388 KB
testcase_36 AC 140 ms
7,040 KB
testcase_37 AC 42 ms
5,508 KB
testcase_38 AC 34 ms
5,588 KB
testcase_39 AC 108 ms
9,124 KB
testcase_40 AC 117 ms
6,992 KB
testcase_41 AC 76 ms
5,744 KB
testcase_42 AC 71 ms
5,740 KB
testcase_43 AC 66 ms
6,320 KB
testcase_44 AC 25 ms
5,448 KB
testcase_45 AC 66 ms
5,840 KB
testcase_46 AC 11 ms
5,072 KB
testcase_47 AC 369 ms
9,156 KB
testcase_48 AC 12 ms
5,276 KB
testcase_49 AC 12 ms
5,148 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
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 = 300
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