結果

問題 No.154 市バス
ユーザー yozayoza
提出日時 2016-06-12 13:47:32
言語 Ruby
(3.3.0)
結果
AC  
実行時間 533 ms / 2,000 ms
コード長 609 bytes
コンパイル時間 55 ms
コンパイル使用メモリ 7,424 KB
実行使用メモリ 13,440 KB
最終ジャッジ日時 2024-04-21 09:35:00
合計ジャッジ時間 4,251 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 478 ms
13,184 KB
testcase_01 AC 489 ms
13,312 KB
testcase_02 AC 479 ms
13,312 KB
testcase_03 AC 374 ms
13,440 KB
testcase_04 AC 448 ms
13,440 KB
testcase_05 AC 78 ms
12,160 KB
testcase_06 AC 78 ms
12,160 KB
testcase_07 AC 533 ms
13,440 KB
testcase_08 AC 78 ms
12,160 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

def solve(s)
  last_w = 0
  last_g = 0
  counter = {W: 0, G: 0}
  s.each_char.with_index do |c, i|
    if c == 'W'
      last_w = i
      counter[:W] += 1
    elsif c == 'G'
      if counter[:W] == 0
        return false
      else
        last_g = i
        counter[:W] -= 1
        counter[:G] += 1
      end
    else
      if counter[:G] == 0
        return false
      else
        counter[:G] -= 1
      end
    end
  end
  if last_w > last_g or counter[:G] != 0 or s[-1] != 'R'
    return false
  end
  return true
end

n = gets.to_i

n.times do
  puts solve(gets.chomp) ? 'possible' : 'impossible'
end
0