とりま超ナイーブバージョン
($mx,$my) = gets.split(" ").map(&:to_i)
$mem = []
$mx.times do
$mem << gets.chomp.bytes.map(&:chr).map(&:to_i)
end
def count(x,y)
k = 0
$mx.times do |i|
$my.times do |j|
if $mem[i][j] == 0
k += 1 if drawable(i,j,x,y)
end
end
end
puts k
end
def drawable(mx,my,x,y)
return false if mx + x > $mx
return false if my + y > $my
x.times do |i|
y.times do |j|
return false if $mem[mx + i][my + j] == 1
end
end
return true
end
widgets = gets.to_i
widgets.times do
count(*(gets.split(" ").map(&:to_i)))
end
テスト4でタイムアウト。42点。