結果
問題 | No.179 塗り分け |
ユーザー |
|
提出日時 | 2016-03-31 00:35:11 |
言語 | Ruby (3.4.1) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,615 bytes |
コンパイル時間 | 84 ms |
コンパイル使用メモリ | 7,424 KB |
実行使用メモリ | 21,024 KB |
最終ジャッジ日時 | 2024-10-03 03:18:32 |
合計ジャッジ時間 | 7,577 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 6 |
other | WA * 2 TLE * 1 -- * 37 |
コンパイルメッセージ
Syntax OK
ソースコード
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'