結果

問題 No.179 塗り分け
ユーザー d2verb
提出日時 2017-12-27 03:21:54
言語 Crystal
(1.14.0)
結果
WA  
実行時間 -
コード長 706 bytes
コンパイル時間 11,817 ms
コンパイル使用メモリ 295,872 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-06-30 19:13:20
合計ジャッジ時間 13,215 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 5 WA * 1
other AC * 39 WA * 1
権限があれば一括ダウンロードができます
コンパイルメッセージ
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