結果

問題 No.179 塗り分け
ユーザー shi-moshi-mo
提出日時 2016-03-31 00:35:11
言語 Ruby
(3.3.0)
結果
WA  
実行時間 -
コード長 1,615 bytes
コンパイル時間 49 ms
コンパイル使用メモリ 7,552 KB
実行使用メモリ 21,156 KB
最終ジャッジ日時 2024-04-14 06:02:48
合計ジャッジ時間 7,861 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 88 ms
12,288 KB
testcase_01 AC 89 ms
12,160 KB
testcase_02 AC 88 ms
12,160 KB
testcase_03 AC 89 ms
12,288 KB
testcase_04 AC 91 ms
12,160 KB
testcase_05 AC 1,643 ms
13,312 KB
testcase_06 WA -
testcase_07 WA -
testcase_08 TLE -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
testcase_39 -- -
testcase_40 -- -
testcase_41 -- -
testcase_42 -- -
testcase_43 -- -
testcase_44 -- -
testcase_45 -- -
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

h, w = gets.split.map(&:to_i)
s = h.times.map{ gets.chomp!.split(//).map{|c| '#' == c } }

class Image
  def initialize(a)
    @a = a.map{|row| row.clone }
    @row_size = @a.length
    @column_size = @a[0].length
  end
  attr_reader :row_size, :column_size

  def [](x, y)
    @a[x][y]
  end

  def []=(x, y, val)
    @a[x][y] = val
  end

  def clone
    self.class.new(@a.map{|row| row.clone })
  end

  def shift(dx, dy)
    row_ids = (0...row_size).to_a
    row_ids.reverse! if 0 <= dx

    col_ids = (0...column_size).to_a
    col_ids.reverse! if 0 <= dy

    row_ids.each do |i|
      col_ids.each do |j|
        self[i, j] = include_index?(i-dx, j-dy) ? self[i-dx, j-dy] : false
      end
    end
    self
  end

  def include_index?(i, j)
    0 <= i && i < row_size && 0 <= j && j < column_size
  end

  def &(other)
    result = self.clone
    each_index do |i, j|
      result[i, j] &= other[i, j]
    end
    result
  end

  def ^(other)
    result = self.clone
    each_index do |i, j|
      result[i, j] ^= other[i, j]
    end
    result
  end

  def ==(other)
    each_index do |i, j|
      return false if self[i, j] != other[i, j]
    end
    true
  end

  def each_index
    row_size.times do |i|
      column_size.times do |j|
        yield(i, j)
      end
    end
  end
end

image = Image.new(s)
ok = false
h.times do |dx|
  break if ok
  ((1-w)...w).each do |dy|
    break if ok
    next if 0 == dx && 0 == dy

    mask = image.clone.shift(dx, dy)
    half_image = (image & mask).shift(-dx, -dy)
    ok |= image == (half_image ^ half_image.clone.shift(dx, dy))
  end
end
puts ok ? 'YES' : 'NO'
0