結果

問題 No.179 塗り分け
ユーザー d2verbd2verb
提出日時 2017-12-27 02:50:11
言語 Crystal
(1.11.2)
結果
WA  
実行時間 -
コード長 970 bytes
コンパイル時間 18,706 ms
コンパイル使用メモリ 256,180 KB
実行使用メモリ 5,308 KB
最終ジャッジ日時 2023-09-13 09:29:43
合計ジャッジ時間 19,675 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
4,384 KB
testcase_01 AC 2 ms
4,416 KB
testcase_02 AC 2 ms
4,400 KB
testcase_03 AC 3 ms
4,404 KB
testcase_04 AC 2 ms
4,396 KB
testcase_05 AC 9 ms
5,216 KB
testcase_06 AC 2 ms
4,436 KB
testcase_07 WA -
testcase_08 AC 56 ms
5,180 KB
testcase_09 WA -
testcase_10 AC 3 ms
4,576 KB
testcase_11 AC 2 ms
4,496 KB
testcase_12 AC 62 ms
5,132 KB
testcase_13 AC 3 ms
4,556 KB
testcase_14 AC 3 ms
4,556 KB
testcase_15 AC 2 ms
4,408 KB
testcase_16 AC 3 ms
4,408 KB
testcase_17 AC 2 ms
4,420 KB
testcase_18 AC 4 ms
5,048 KB
testcase_19 AC 4 ms
5,080 KB
testcase_20 AC 53 ms
5,152 KB
testcase_21 AC 58 ms
5,084 KB
testcase_22 AC 56 ms
5,136 KB
testcase_23 AC 3 ms
4,544 KB
testcase_24 AC 54 ms
5,132 KB
testcase_25 AC 3 ms
4,856 KB
testcase_26 WA -
testcase_27 AC 83 ms
5,136 KB
testcase_28 WA -
testcase_29 AC 94 ms
5,144 KB
testcase_30 WA -
testcase_31 AC 101 ms
5,220 KB
testcase_32 AC 23 ms
5,052 KB
testcase_33 AC 88 ms
5,124 KB
testcase_34 WA -
testcase_35 AC 95 ms
5,144 KB
testcase_36 AC 3 ms
4,444 KB
testcase_37 AC 2 ms
4,404 KB
testcase_38 AC 3 ms
4,408 KB
testcase_39 AC 3 ms
4,412 KB
testcase_40 AC 3 ms
4,408 KB
testcase_41 AC 2 ms
4,408 KB
testcase_42 AC 2 ms
4,412 KB
testcase_43 AC 5 ms
4,856 KB
testcase_44 AC 13 ms
5,080 KB
testcase_45 AC 2 ms
4,692 KB
権限があれば一括ダウンロードができます

ソースコード

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.upto(h-1) do |dy|
    0.upto(w-1) do |dx|
      if dx == 0 && dy == 0
        next
      end

      _rect = rect.clone
      ok = true

      0.upto(h-1) do |y|
        0.upto(w-1) do |x|
          if _rect[y][x] == "."
            next
          end

          ny = y + dy
          nx = x + dx

          if nx >= w || ny >= h
            next
          end

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

        end
      end

      0.upto(h-1) do |y|
        0.upto(w-1) do |x|
          if _rect[y][x] == "#"
            ok = false
          end
        end
      end

      if ok
        return true
      end
    end
  end
  return false
end

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