結果
| 問題 | 
                            No.179 塗り分け
                             | 
                    
| コンテスト | |
| ユーザー | 
                             | 
                    
| 提出日時 | 2015-04-06 00:50:04 | 
| 言語 | Ruby  (3.4.1)  | 
                    
| 結果 | 
                             
                                WA
                                 
                             
                            
                         | 
                    
| 実行時間 | - | 
| コード長 | 837 bytes | 
| コンパイル時間 | 212 ms | 
| コンパイル使用メモリ | 7,552 KB | 
| 実行使用メモリ | 77,952 KB | 
| 最終ジャッジ日時 | 2024-10-02 13:39:03 | 
| 合計ジャッジ時間 | 22,678 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge3 / judge1 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 5 WA * 1 | 
| other | AC * 26 WA * 12 RE * 2 | 
コンパイルメッセージ
Syntax OK
ソースコード
require 'set'
H, W = gets.split.map(&:to_i)
class << MAP = Array.new(H) { gets.strip }
  def ok?(dx, dy)
    d = dy * W + dx
    bs = blacks - blacks.map {|i| i + d }
    bs.size == blacks.size / 2 && bs.all? {|i| flat[i + d] == 35 }
  end
  def solve
    ax, ay, bx, by = aabb
    (1..bx - ax).each do |dx|
      (1..by - ay).each do |dy|
        return :YES if ok?(dx, dy)
      end
    end
    :NO
  end
  def flat
    @flat ||= map(&:bytes).flatten
  end
  def blacks
    @blacks ||= Set.new(flat.each_with_index.map {|cell, i| i if cell == 35 }.compact)
  end
  def aabb
    ax = ay = bx = by = nil
    blacks.each do |i|
      y, x = i.divmod(W)
      ax = x if !ax || ax > x
      ay = y if !ay || ay > y
      bx = x if !bx || bx < x
      by = y if !by || by < y
    end
    return ax, ay, bx, by
  end
end
puts MAP.solve