結果

問題 No.154 市バス
ユーザー steek79steek79
提出日時 2015-10-14 16:59:55
言語 Python2
(2.7.18)
結果
AC  
実行時間 282 ms / 2,000 ms
コード長 717 bytes
コンパイル時間 66 ms
コンパイル使用メモリ 6,940 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-21 08:50:39
合計ジャッジ時間 2,627 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 280 ms
6,816 KB
testcase_01 AC 282 ms
6,940 KB
testcase_02 AC 279 ms
6,944 KB
testcase_03 AC 205 ms
6,944 KB
testcase_04 AC 262 ms
6,944 KB
testcase_05 AC 11 ms
6,944 KB
testcase_06 AC 11 ms
6,940 KB
testcase_07 AC 280 ms
6,940 KB
testcase_08 AC 12 ms
6,940 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#!/usr/bin/python
# -*- coding: utf-8 -*-

# roiti46 さんのをカンニング

T = input()
for t in range(T):
    inp = raw_input()
    w = last = 0
    needG = False
    # last: 要終電本数
    # needG: 要緑 t/f
    
    for s in inp: #緑より多く赤 or 白より多く緑 はだめ
        if s == 'G':
            last += 1
            w -= 1
            needG = False
        elif s == 'R':
            last -= 1
        else: #s == 'W'
            w += 1
            needG = True
        
        if last < 0 or w < 0: 
            print 'impossible'
            break
    
    else:
        if last == 0 and needG == False: 
            print 'possible'
        else:
            print 'impossible'
0