結果

問題 No.179 塗り分け
ユーザー d2verbd2verb
提出日時 2017-12-27 04:48:33
言語 Crystal
(1.11.2)
結果
AC  
実行時間 174 ms / 3,000 ms
コード長 797 bytes
コンパイル時間 18,986 ms
コンパイル使用メモリ 256,560 KB
実行使用メモリ 5,256 KB
最終ジャッジ日時 2023-09-13 09:29:20
合計ジャッジ時間 23,331 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
4,380 KB
testcase_01 AC 2 ms
4,484 KB
testcase_02 AC 3 ms
4,436 KB
testcase_03 AC 2 ms
4,464 KB
testcase_04 AC 3 ms
4,480 KB
testcase_05 AC 13 ms
5,152 KB
testcase_06 AC 6 ms
5,144 KB
testcase_07 AC 174 ms
5,256 KB
testcase_08 AC 106 ms
5,256 KB
testcase_09 AC 105 ms
5,200 KB
testcase_10 AC 54 ms
5,192 KB
testcase_11 AC 47 ms
5,148 KB
testcase_12 AC 95 ms
5,144 KB
testcase_13 AC 3 ms
4,872 KB
testcase_14 AC 3 ms
4,784 KB
testcase_15 AC 3 ms
4,496 KB
testcase_16 AC 3 ms
4,424 KB
testcase_17 AC 3 ms
4,536 KB
testcase_18 AC 55 ms
5,208 KB
testcase_19 AC 55 ms
5,144 KB
testcase_20 AC 104 ms
5,136 KB
testcase_21 AC 114 ms
5,152 KB
testcase_22 AC 135 ms
5,148 KB
testcase_23 AC 55 ms
5,188 KB
testcase_24 AC 106 ms
5,200 KB
testcase_25 AC 55 ms
5,136 KB
testcase_26 AC 63 ms
5,148 KB
testcase_27 AC 104 ms
5,188 KB
testcase_28 AC 56 ms
5,152 KB
testcase_29 AC 106 ms
5,196 KB
testcase_30 AC 81 ms
5,184 KB
testcase_31 AC 105 ms
5,224 KB
testcase_32 AC 67 ms
5,136 KB
testcase_33 AC 105 ms
5,212 KB
testcase_34 AC 64 ms
5,252 KB
testcase_35 AC 105 ms
5,196 KB
testcase_36 AC 3 ms
4,480 KB
testcase_37 AC 2 ms
4,532 KB
testcase_38 AC 3 ms
4,464 KB
testcase_39 AC 3 ms
4,496 KB
testcase_40 AC 3 ms
4,480 KB
testcase_41 AC 3 ms
4,536 KB
testcase_42 AC 3 ms
4,524 KB
testcase_43 AC 6 ms
5,136 KB
testcase_44 AC 16 ms
5,232 KB
testcase_45 AC 4 ms
4,924 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
In Main.cr:8:22

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

In Main.cr:15:18

 15 | (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)
  (-(h-1)...h).to_a.product((-(w-1)...w).to_a) do |dy, dx|
    next if dx == 0 && dy == 0

    _rect = rect.clone
    ok = true
    touched = false

    (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 < 0 || nx >= w || ny < 0 || ny >= h
        ok = false
        break
      end

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

    ok = ok && touched
    return true if ok
  end
  return false
end

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