結果

問題 No.345 最小チワワ問題
ユーザー simansiman
提出日時 2016-03-19 21:40:13
言語 Ruby
(3.4.1)
結果
AC  
実行時間 91 ms / 2,000 ms
コード長 578 bytes
コンパイル時間 44 ms
コンパイル使用メモリ 7,552 KB
実行使用メモリ 12,288 KB
最終ジャッジ日時 2024-09-25 11:41:13
合計ジャッジ時間 4,283 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 29
権限があれば一括ダウンロードができます
コンパイルメッセージ
Main.rb:25: warning: ambiguous first argument; put parentheses or a space even after `-' operator
Syntax OK

ソースコード

diff #

class Yukicoder
  def initialize
    s = gets.chomp
    n = s.size
    inf = 9999
    w1 = -1
    w2 = -1
    min_length = inf

    s.chars.reverse.each_with_index do |ch, index|
      if ch == 'w'
        if w2 == -1
          w2 = n - index - 1
        elsif w1 == -1
          w1 = n - index - 1
        else
          w1, w2 = (n - index - 1), w1
        end
      elsif ch == 'c' && w1 != -1
        min_length = [min_length, w2 - (n - index - 2)].min
      end
    end

    if min_length == inf
      puts -1
    else
      puts min_length
    end
  end
end

Yukicoder.new
0