結果

問題 No.154 市バス
ユーザー nebukuro09
提出日時 2016-09-08 10:27:26
言語 Python2
(2.7.18)
結果
WA  
実行時間 -
コード長 606 bytes
コンパイル時間 44 ms
コンパイル使用メモリ 6,912 KB
実行使用メモリ 6,400 KB
最終ジャッジ日時 2024-10-13 08:43:00
合計ジャッジ時間 1,731 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 7 WA * 1
権限があれば一括ダウンロードができます

ソースコード

diff #

for _ in xrange(input()):
    s = raw_input()
    w, g, r = s.count('W'), s.count('G'), s.count('R')
    if w == 0 or g == 0 or r == 0:
        print 'impossible'
        continue
    if w < r or w < g:
        print 'impossible'
        continue
    if s.rindex('W') > s.rindex('G') or s.rindex('W') > s.rindex('R'):
        print 'impossible'
        continue
    
    left = 0
    for c in s:
        if c == 'G':
            left += 1
        elif c == 'R':
            left -= 1
        if left < 0:
            break
    if left != 0:
        print 'impossible'
        continue
    print 'possible'
0