問題はこちらのリンクから。
http://qiita.com/Nabetani/items/936e7885f4c607472060
会場では、時間制限があるので
http://qiita.com/nidouchi/items/ea73c5fee91228842b3f
こんなのしか出来なかったのですが懇親会で酒を飲んで色々な話をすると、ましな実装を思いつきます。
def solve(q)
walls = q.chars.map(&:to_i)
pool = walls.map{|sz| sz==0 ? ['H']*walls.max : ['B']*sz + ['X']*(walls.max-sz)}.transpose.map(&:join)
pool.map{|line| line.gsub(/(BX+)+B/){|s| s.gsub('X','W')}}.join.count('W')
end
DATA.readlines.each do |line|
no,q,a,d = line.chop.split(/\s+/)
ans = solve(q)
print no + "\t" + ans.to_s
puts ans == a.to_i ? ' o' : ' x'
end
__END__
0 83141310145169154671122 24
1 923111128 45
2 923101128 1