結果

問題 No.154 市バス
ユーザー nebukuro09nebukuro09
提出日時 2016-10-05 10:35:46
言語 Python2
(2.7.18)
結果
AC  
実行時間 258 ms / 2,000 ms
コード長 700 bytes
コンパイル時間 48 ms
コンパイル使用メモリ 7,040 KB
実行使用メモリ 6,528 KB
最終ジャッジ日時 2024-04-21 09:57:25
合計ジャッジ時間 2,190 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 257 ms
6,400 KB
testcase_01 AC 256 ms
6,400 KB
testcase_02 AC 255 ms
6,400 KB
testcase_03 AC 76 ms
6,400 KB
testcase_04 AC 258 ms
6,400 KB
testcase_05 AC 11 ms
6,528 KB
testcase_06 AC 11 ms
6,528 KB
testcase_07 AC 195 ms
6,400 KB
testcase_08 AC 11 ms
6,528 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def solve(s):
    numG, numR = s.count('G'), s.count('R')
    if numG != numR or numG == 0:
        return False
    W, G, R = 0, 0, 0
    Wassign = 0
    for light in s:
        if light == 'R':
            R += 1
        elif light == 'G':
            G += 1
            Wassign += 1
        else:
            W += 1
            Wassign = max(Wassign-1, 0)
        if (R == 0 or G == 0) and W > 0:
            return False
        if G > R:
            return False
    if Wassign > 0:
        return False
    if G == numG and R == numR and W >= numG:
        return True
    else:
        return False

for t in xrange(input()):
    print 'possible' if solve(raw_input()[::-1]) else 'impossible'
0