結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,456 KB
testcase_01 AC 2 ms
4,408 KB
testcase_02 AC 2 ms
4,412 KB
testcase_03 WA -
testcase_04 AC 2 ms
4,392 KB
testcase_05 AC 6 ms
5,084 KB
testcase_06 AC 2 ms
4,388 KB
testcase_07 AC 48 ms
5,128 KB
testcase_08 AC 30 ms
5,140 KB
testcase_09 AC 30 ms
5,140 KB
testcase_10 AC 3 ms
4,532 KB
testcase_11 AC 2 ms
4,616 KB
testcase_12 WA -
testcase_13 AC 3 ms
4,588 KB
testcase_14 AC 3 ms
4,592 KB
testcase_15 AC 2 ms
4,468 KB
testcase_16 AC 2 ms
4,404 KB
testcase_17 AC 2 ms
4,428 KB
testcase_18 AC 4 ms
5,216 KB
testcase_19 AC 4 ms
5,132 KB
testcase_20 AC 30 ms
5,172 KB
testcase_21 AC 31 ms
5,132 KB
testcase_22 AC 37 ms
5,180 KB
testcase_23 AC 3 ms
4,524 KB
testcase_24 AC 31 ms
5,092 KB
testcase_25 AC 3 ms
4,868 KB
testcase_26 AC 7 ms
5,132 KB
testcase_27 AC 30 ms
5,084 KB
testcase_28 AC 5 ms
5,144 KB
testcase_29 AC 30 ms
5,140 KB
testcase_30 AC 15 ms
5,172 KB
testcase_31 AC 30 ms
5,124 KB
testcase_32 AC 11 ms
5,140 KB
testcase_33 AC 30 ms
5,148 KB
testcase_34 AC 9 ms
5,176 KB
testcase_35 AC 31 ms
5,164 KB
testcase_36 AC 3 ms
4,448 KB
testcase_37 AC 2 ms
4,552 KB
testcase_38 AC 3 ms
4,444 KB
testcase_39 AC 3 ms
4,376 KB
testcase_40 AC 2 ms
4,440 KB
testcase_41 AC 3 ms
4,420 KB
testcase_42 AC 3 ms
4,448 KB
testcase_43 AC 4 ms
5,220 KB
testcase_44 AC 6 ms
5,140 KB
testcase_45 AC 3 ms
4,676 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:14:18

 14 | (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
    touched = false

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

      ny = (y + dy) % h
      nx = (x + dx) % w

      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