結果

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

ソースコード

diff #

N = gets.to_i
tmp = "#{gets.chomp}#{gets.chomp}".chars.map { |c| c == 'o' ? true : false }
ADD = Array.new(7) { 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