結果

問題 No.154 市バス
ユーザー wotsushiwotsushi
提出日時 2017-01-21 14:19:50
言語 Ruby
(3.3.0)
結果
AC  
実行時間 493 ms / 2,000 ms
コード長 505 bytes
コンパイル時間 129 ms
コンパイル使用メモリ 7,552 KB
実行使用メモリ 13,696 KB
最終ジャッジ日時 2024-04-21 10:06:51
合計ジャッジ時間 4,209 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 486 ms
13,696 KB
testcase_01 AC 493 ms
13,440 KB
testcase_02 AC 488 ms
13,568 KB
testcase_03 AC 408 ms
13,568 KB
testcase_04 AC 490 ms
13,568 KB
testcase_05 AC 83 ms
12,160 KB
testcase_06 AC 83 ms
12,288 KB
testcase_07 AC 444 ms
13,568 KB
testcase_08 AC 88 ms
12,160 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

T = gets.to_i
S = T.times.map {gets.chomp}

def f(s)
  r = 0
  g = 0
  w = 0
  s.reverse.each_char do |c|
    if c == "R"
      r += 1
    elsif c == "G"
      if r == 0
        return "impossible"
      else
        r -= 1
        g += 1
      end
    elsif c == "W"
      if g == 0 and w == 0
        return "impossible"
      else
        g = [g - 1, 0].max
        w += 1
      end
    end
  end
  if r == 0 and g == 0
    "possible"
  else
    "impossible"
  end
end

ans = S.map {|s| f(s)}
puts ans
0