結果

問題 No.459 C-VS for yukicoder
ユーザー miraxial
提出日時 2016-12-10 00:56:01
言語 Ruby
(3.4.1)
結果
AC  
実行時間 428 ms / 2,000 ms
コード長 765 bytes
コンパイル時間 586 ms
コンパイル使用メモリ 7,552 KB
実行使用メモリ 17,920 KB
最終ジャッジ日時 2024-11-28 20:56:22
合計ジャッジ時間 10,668 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 58
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

h,w,n=gets.split.map &:to_i
a=[]
c=[0]*w
h.times do |i|
  a<< g=gets.chomp
  w.times do |i|
    c[i]+=1 if g[i]==?#
  end
end
d=[0]*w
v=*$<.map(&:to_i)
v.each do |e|
  d[e]+=1
  d[e+1]+=1
  d[e+2]+=1
end
n.times do |i|
  v[i]=[v[i],i]
end
w=v.sort
f=[]
w.each do |e|
  g=[]
  3.times do |i|
    t=e[0]+i
    d[t]-=1
    if d[t]==0
      g<< c[t]
    else
      if d[t]*3<c[t]
        g<< c[t]-d[t]*3
        c[t]=d[t]*3
      else
        g<< 0
      end
    end
  end
  if g==[0,0,0]
    3.times do |i|
      t=e[0]+i
      if c[t]!=0
        g[i]+=1
        c[t]-=1
        break
      end
    end
  end
  f<< g+[e[1]]
end
f.sort!{|a,b|a[3]<=>b[3]}
f.each do |e|
  3.times do |i|
    s=""
    3.times do |j|
      s+=e[j]>=3-i ? ?#:?.
    end
    puts s
  end
end
0