LoginSignup
2
2

More than 5 years have passed since last update.

行列のできるラーメン屋

Last updated at Posted at 2015-10-24

KUPCの問題を見る前にこちらの問題を見てしまったため、コーディング時間は20分ですが実際に掛かった時間は不明です。すみません。

問題文には明記されていませんが、たとえば[8,1]卓に2人を入れることは可能です。
あと、最後の出力をするときは人を掃き出してはいけないのがポイント。最初clear_table()をtake_turn()に組み込んではまりました。

採点は、
https://github.com/cielavenir/procon/blob/c348846381e01a638a1854c24c8658e5a09c522b/hena/tyama_hena_validator.cpp
https://github.com/cielavenir/procon/blob/c348846381e01a638a1854c24c8658e5a09c522b/hena/tyama_hena_validator_test_mtsmfm151022.cpp
https://github.com/cielavenir/procon/blob/c348846381e01a638a1854c24c8658e5a09c522b/streambuf_fromfile.h
を用意して、

g++ -O2 tyama_hena_validator.cpp tyama_hena_validator_test_mtsmfm151022.cpp -I. -DSTREAM_PORTABLE
として、a.out ruby mtsmfm151022.rbとします。
(採点プログラムv2は使えません)

mtsmfm151022.rb
#!/usr/bin/env ruby
#https://gist.github.com/mtsmfm/4b8ffb53ffac055f5843
N=8
def fill_table(a,n)
    idx=N.times.find{|st|n.times.all?{|i|a[(st+i)%N]==0}}
    if idx
        n.times{|i|a[(idx+i)%N]=1}
        true
    else
        false
    end
end
def clear_table(a)
    N.times{|i|
        a[i]=0 if a[i]==4
    }
end
def take_turn(a)
    N.times{|i|
        a[i]+=1 if a[i]>0
    }
end

if __FILE__==$0
    while gets
        a=[0]*N
        $_.chomp.chars{|c|
            clear_table(a)
            f=fill_table(a,c.to_i)
            take_turn(a)
            redo if !f
        }
        puts a.map{|e|e==0 ? 0 : 1}*'' 
        STDOUT.flush
    end
end
2
2
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
2
2