結果

問題 No.154 市バス
ユーザー roiti46
提出日時 2015-02-18 00:02:47
言語 Python2
(2.7.18)
結果
AC  
実行時間 273 ms / 2,000 ms
コード長 473 bytes
コンパイル時間 664 ms
コンパイル使用メモリ 6,912 KB
実行使用メモリ 6,272 KB
最終ジャッジ日時 2024-10-13 06:31:25
合計ジャッジ時間 2,456 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 8
権限があれば一括ダウンロードができます

ソースコード

diff #

T = int(raw_input())
for loop in xrange(T):
    S = raw_input()
    w = last = cnt = 0
    needG = False
    for s in S:
        if   s == "G":
            last += 1
            w -= 1
            needG = False
        elif s == "R":
            last -= 1
        else:
            w += 1
            needG = True
        if last < 0 or w < 0:
            print "impossible"
            break
    else:
        print "possible" if last == 0 and not needG else "impossible"
0