結果

問題 No.154 市バス
コンテスト
ユーザー TANIGUCHI Kousuke
提出日時 2015-11-06 16:40:56
言語 Ruby
(4.0.2)
コンパイル:
ruby -w -c _filename_
実行:
ruby _filename_
結果
AC  
実行時間 302 ms / 2,000 ms
コード長 668 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 110 ms
コンパイル使用メモリ 8,960 KB
実行使用メモリ 15,488 KB
最終ジャッジ日時 2026-04-30 16:34:18
合計ジャッジ時間 3,124 ms
ジャッジサーバーID
(参考情報)
judge3_0 / judge2_1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 8
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #
raw source code

n = gets.to_i
n.times do
    lines = [0,0,0,0]
    s = gets.chomp.chars.reverse
    s.each do |c|
        if c == 'R'
            lines[0] += 1
        elsif c == 'G'
            if lines[0] > 0
                lines[0] -= 1
                lines[1] += 1
            else
                lines[3] = 1
                break
            end
        else
            if lines[1] > 0
                lines[1] -= 1
                lines[2] += 1
            elsif lines[2] > 0
                
            else
                lines[3] = 1
                break;
            end
        end
    end
    puts [0,1,3].all? {|i| lines[i] == 0 } ? "possible" : "impossible"
end
0