結果

問題 No.204 ゴールデン・ウィーク(2)
ユーザー koyopro
提出日時 2019-12-13 00:56:55
言語 Ruby
(3.4.1)
結果
AC  
実行時間 95 ms / 1,000 ms
コード長 736 bytes
コンパイル時間 224 ms
コンパイル使用メモリ 7,552 KB
実行使用メモリ 12,416 KB
最終ジャッジ日時 2024-06-26 02:02:56
合計ジャッジ時間 5,983 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 46
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

N = gets.to_i
tmp = "#{gets.chomp}#{gets.chomp}".chars.map { |c| c == 'o' ? true : false }
ADD = Array.new(14) { false }
LIST = ADD + tmp + ADD

# puts LIST.to_s

def count_from(list, index)
  c = 0
  i = index
  while i < list.size && list[i]
    c += 1
    i += 1
  end
  c
end

def count(list)
  a = Array.new(list.size) do |i|
    count_from(list, i)
  end
  # puts "#{list} -> #{a.max}"
  a.max
end

xidxs = LIST.each_index.select { |i| !LIST[i] }

# puts xidxs.to_s

ans = count(LIST)
xidxs.each do |start|
  remain = N
  list = LIST.map.with_index { |r, i|
    if i >= start && remain > 0 && !r
      remain -= 1
      true
    else
      remain = 0 if i >= start
      r
    end
  }
  ans = [count(list), ans].max
end

puts ans
0