0
0

More than 5 years have passed since last update.

第13回オフラインリアルタイムどう書くの問題をRubyで解く、その2

Posted at

問題はこちらのリンクから。
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   
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0