結果

問題 No.154 市バス
ユーザー nebukuro09nebukuro09
提出日時 2016-09-08 10:27:26
言語 Python2
(2.7.18)
結果
WA  
実行時間 -
コード長 606 bytes
コンパイル時間 408 ms
コンパイル使用メモリ 6,948 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-21 09:55:32
合計ジャッジ時間 1,878 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 155 ms
6,400 KB
testcase_01 AC 158 ms
6,400 KB
testcase_02 AC 159 ms
6,272 KB
testcase_03 AC 116 ms
6,400 KB
testcase_04 WA -
testcase_05 AC 10 ms
6,272 KB
testcase_06 AC 9 ms
6,400 KB
testcase_07 AC 155 ms
6,272 KB
testcase_08 AC 10 ms
6,272 KB
権限があれば一括ダウンロードができます

ソースコード

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