Last active
August 29, 2015 13:59
-
-
Save parrot-studio/10815136 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
height, width = gets.split(' ').map(&:to_i) | |
# bitとして扱う | |
lines = [] | |
(1..height).each do |h| | |
lines << gets.chomp.to_i(2) | |
end | |
# 対象を解析 | |
targets = {} | |
tickets = [] | |
gets.to_i.times do | |
wh, ww = gets.split(' ').map(&:to_i) | |
tickets << [ww, wh] | |
targets[ww] = true if ww <= width | |
end | |
# 盤面をparse | |
memo = Hash.new{|h,k| h[k] = Hash.new(0)} | |
targets.keys.each do |tw| | |
wm = memo[tw] | |
val = ("1" * tw).to_i(2) | |
(width - tw + 1).times do | |
count = 0 | |
height.times do |vi| | |
if lines[vi] & val == 0 | |
count += 1 | |
else | |
(1..count).each{|c| wm[c] += (count - c + 1)} if count > 0 | |
count = 0 | |
end | |
end | |
(1..count).each{|c| wm[c] += (count - c + 1)} if count > 0 | |
val = (val << 1) | |
end | |
end | |
# 最終結果 | |
tickets.each do |key| | |
puts memo[key.first][key.last] | |
end |
6eb329 => http://paiza.jp/poh/paizen/result/0a1301346eadae7ae26515e64a786e7f
evalなんて馬鹿げた手を使っていたら、そりゃ遅くなるよ(´・ω・)(・ω・`)ネー
3650f8 => http://paiza.jp/poh/paizen/result/82967b508c0f18216f02892f36adb69d
びっくりするほど変わらなかったΣ(゚Д゚)ガーン
9b15a2 => http://paiza.jp/poh/paizen/result/0ba0a0c1b970fb72525886d3abc42e15
ちょっといじったらSSSに到達(; д ) ゚ ゚
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
最終的な解答だけ残して削除