結果

問題 No.506 限られたジャパリまん
ユーザー char134217728char134217728
提出日時 2017-08-11 07:10:51
言語 Ruby
(3.3.0)
結果
AC  
実行時間 495 ms / 2,000 ms
コード長 743 bytes
コンパイル時間 287 ms
コンパイル使用メモリ 11,176 KB
実行使用メモリ 20,796 KB
最終ジャッジ日時 2023-09-10 12:55:28
合計ジャッジ時間 5,889 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 86 ms
15,108 KB
testcase_01 AC 85 ms
15,144 KB
testcase_02 AC 86 ms
15,140 KB
testcase_03 AC 87 ms
15,036 KB
testcase_04 AC 90 ms
15,416 KB
testcase_05 AC 85 ms
15,144 KB
testcase_06 AC 85 ms
15,028 KB
testcase_07 AC 89 ms
15,512 KB
testcase_08 AC 495 ms
20,788 KB
testcase_09 AC 267 ms
17,604 KB
testcase_10 AC 92 ms
15,348 KB
testcase_11 AC 460 ms
20,088 KB
testcase_12 AC 311 ms
17,216 KB
testcase_13 AC 84 ms
15,140 KB
testcase_14 AC 88 ms
15,132 KB
testcase_15 AC 84 ms
15,140 KB
testcase_16 AC 400 ms
20,796 KB
testcase_17 AC 97 ms
15,512 KB
testcase_18 AC 99 ms
15,280 KB
testcase_19 AC 123 ms
16,408 KB
testcase_20 AC 175 ms
19,616 KB
testcase_21 AC 110 ms
16,148 KB
testcase_22 AC 197 ms
19,688 KB
testcase_23 AC 156 ms
18,632 KB
testcase_24 AC 93 ms
15,176 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

h, w, k, p = gets.split.map &:to_i
m = {}
f = k.times.map do |i|
  x, y, n = gets.split
  m[33 * x.to_i + y.to_i] = i
  n
end
comb = [*0...k].combination(p).to_a
ans = [0, []]
comb.each do |arr|
  a = []
  (h+1).times do |_h|
    a << []
    (w+1).times do |_w|
      if _h == 0 && _w == 0
        a[_h][_w] = 1
        next
      end
      i = m[33 * _h + _w]
      if i && !arr.index(i)
        a[_h][_w] = 0
        next
      end
      if _h == 0
        a[_h][_w] = a[_h][_w-1]
        next
      end
      if _w == 0
        a[_h][_w] = a[_h-1][_w]
        next
      end
      a[_h][_w] = a[_h-1][_w] + a[_h][_w-1]
    end
  end
  if ans[0] < a[h][w]
    ans = [a[h][w], arr]
  end
end
puts ans[0] % (10**9+7)
ans[1].each{|i| puts f[i]}
0