結果

問題 No.179 塗り分け
ユーザー snipsnipsnipsnipsnipsnip
提出日時 2015-04-06 01:13:47
言語 Ruby
(3.3.0)
結果
WA  
実行時間 -
コード長 925 bytes
コンパイル時間 311 ms
コンパイル使用メモリ 7,424 KB
実行使用メモリ 77,776 KB
最終ジャッジ日時 2024-04-10 11:43:14
合計ジャッジ時間 22,421 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 83 ms
12,288 KB
testcase_01 WA -
testcase_02 AC 80 ms
12,416 KB
testcase_03 AC 84 ms
12,160 KB
testcase_04 AC 84 ms
12,416 KB
testcase_05 AC 192 ms
23,168 KB
testcase_06 WA -
testcase_07 RE -
testcase_08 AC 97 ms
12,544 KB
testcase_09 WA -
testcase_10 AC 105 ms
14,080 KB
testcase_11 AC 108 ms
13,824 KB
testcase_12 AC 1,973 ms
77,172 KB
testcase_13 AC 85 ms
12,288 KB
testcase_14 AC 82 ms
12,288 KB
testcase_15 AC 80 ms
12,288 KB
testcase_16 AC 82 ms
12,288 KB
testcase_17 RE -
testcase_18 WA -
testcase_19 WA -
testcase_20 AC 1,113 ms
65,572 KB
testcase_21 AC 175 ms
18,048 KB
testcase_22 AC 129 ms
16,128 KB
testcase_23 AC 86 ms
12,416 KB
testcase_24 AC 121 ms
17,024 KB
testcase_25 AC 112 ms
14,976 KB
testcase_26 WA -
testcase_27 AC 756 ms
50,304 KB
testcase_28 WA -
testcase_29 AC 1,138 ms
73,228 KB
testcase_30 WA -
testcase_31 AC 1,335 ms
75,976 KB
testcase_32 AC 612 ms
44,120 KB
testcase_33 AC 1,389 ms
75,984 KB
testcase_34 WA -
testcase_35 AC 1,527 ms
77,776 KB
testcase_36 AC 81 ms
12,288 KB
testcase_37 AC 80 ms
12,288 KB
testcase_38 AC 85 ms
12,288 KB
testcase_39 AC 94 ms
12,416 KB
testcase_40 AC 97 ms
12,288 KB
testcase_41 AC 92 ms
12,416 KB
testcase_42 AC 80 ms
12,160 KB
testcase_43 AC 106 ms
14,208 KB
testcase_44 AC 204 ms
23,168 KB
testcase_45 AC 84 ms
12,416 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

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 if i % W + dx < W }
    bs.size == blacks.size / 2 && bs.all? {|i| flat[i + d] == 35 }
  end

  def solve
    ax, ay, bx, by = aabb
    (1..by - ay).each do |dy|
      return :YES if ok?(0, dy)
    end
    (1..bx - ax).each do |dx|
      (0..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
0