結果

問題 No.179 塗り分け
ユーザー d2verbd2verb
提出日時 2017-12-27 03:16:27
言語 Crystal
(1.11.2)
結果
WA  
実行時間 -
コード長 699 bytes
コンパイル時間 16,976 ms
コンパイル使用メモリ 257,652 KB
実行使用メモリ 5,236 KB
最終ジャッジ日時 2023-09-13 09:28:29
合計ジャッジ時間 20,012 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,472 KB
testcase_01 AC 3 ms
4,408 KB
testcase_02 AC 3 ms
4,376 KB
testcase_03 AC 2 ms
4,444 KB
testcase_04 AC 2 ms
4,528 KB
testcase_05 AC 6 ms
5,124 KB
testcase_06 AC 3 ms
4,396 KB
testcase_07 WA -
testcase_08 AC 31 ms
5,112 KB
testcase_09 WA -
testcase_10 AC 2 ms
4,528 KB
testcase_11 AC 3 ms
4,504 KB
testcase_12 AC 28 ms
5,172 KB
testcase_13 AC 3 ms
4,620 KB
testcase_14 AC 3 ms
4,596 KB
testcase_15 AC 2 ms
4,384 KB
testcase_16 AC 2 ms
4,376 KB
testcase_17 AC 3 ms
4,396 KB
testcase_18 AC 4 ms
5,084 KB
testcase_19 AC 3 ms
5,056 KB
testcase_20 AC 30 ms
5,140 KB
testcase_21 AC 31 ms
5,124 KB
testcase_22 AC 37 ms
5,096 KB
testcase_23 AC 2 ms
4,480 KB
testcase_24 AC 30 ms
5,052 KB
testcase_25 AC 3 ms
4,728 KB
testcase_26 WA -
testcase_27 AC 30 ms
5,160 KB
testcase_28 WA -
testcase_29 AC 30 ms
5,208 KB
testcase_30 WA -
testcase_31 AC 30 ms
5,112 KB
testcase_32 AC 10 ms
5,216 KB
testcase_33 AC 30 ms
5,084 KB
testcase_34 WA -
testcase_35 AC 31 ms
5,132 KB
testcase_36 AC 2 ms
4,416 KB
testcase_37 AC 2 ms
4,412 KB
testcase_38 AC 2 ms
4,388 KB
testcase_39 AC 2 ms
4,380 KB
testcase_40 AC 3 ms
4,404 KB
testcase_41 AC 2 ms
4,472 KB
testcase_42 AC 2 ms
4,528 KB
testcase_43 AC 4 ms
5,108 KB
testcase_44 AC 6 ms
5,236 KB
testcase_45 AC 3 ms
4,644 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
In Main.cr:8:16

 8 | (0...h).to_a.product((0...w).to_a) do |dy, dx|
                  ^------
Warning: Deprecated Array(Int32)#product. Use `Indexable#each_cartesian(*others : Indexable, &block)` instead

In Main.cr:13:18

 13 | (0...h).to_a.product((0...w).to_a) do |y, x|
                   ^------
Warning: Deprecated Array(Int32)#product. Use `Indexable#each_cartesian(*others : Indexable, &block)` instead

A total of 2 warnings were found.

ソースコード

diff #

h, w = gets.not_nil!.split(" ").map{|x| x.to_i}
rect = [] of Array(String)
1.upto(h) do |i|
  rect << gets.not_nil!.split("")
end

def ok?(rect, h, w)
  (0...h).to_a.product((0...w).to_a) do |dy, dx|
    next if dx == 0 && dy == 0
    _rect = rect.clone
    ok = true

    (0...h).to_a.product((0...w).to_a) do |y, x|
      next if _rect[y][x] == "."
      ny = y + dy
      nx = x + dx

      if nx >= w || ny >= h
        ok = false
        break
      end

      if _rect[y][x] == _rect[ny][nx]
        _rect[y][x] = "."
        _rect[ny][nx] = "."
      else
        ok = false
        break
      end
    end

    return true if ok
  end
  return false
end

puts ok?(rect, h, w) ? "YES" : "NO"
0