結果

問題 No.154 市バス
ユーザー nebukuro09nebukuro09
提出日時 2016-10-05 10:29:28
言語 Python2
(2.7.18)
結果
WA  
実行時間 -
コード長 652 bytes
コンパイル時間 468 ms
コンパイル使用メモリ 6,944 KB
実行使用メモリ 6,940 KB
最終ジャッジ日時 2024-04-21 09:57:23
合計ジャッジ時間 1,982 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 139 ms
6,528 KB
testcase_01 AC 137 ms
6,400 KB
testcase_02 AC 136 ms
6,400 KB
testcase_03 AC 53 ms
6,272 KB
testcase_04 WA -
testcase_05 AC 12 ms
6,400 KB
testcase_06 AC 12 ms
6,400 KB
testcase_07 AC 165 ms
6,400 KB
testcase_08 AC 11 ms
6,400 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
    for light in s:
        if light == 'R':
            R += 1
        elif light == 'G':
            G += 1
        else:
            W += 1
        if (R == 0 or G == 0) and W > 0:
            return False
        if G > R:
            return False
        if G == numG and R == numR and W >= numG:
            return True
    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