結果

問題 No.154 市バス
コンテスト
ユーザー nebukuro09
提出日時 2016-10-05 10:19:41
言語 PyPy2
(7.3.15)
結果
MLE  
実行時間 -
コード長 860 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 131 ms
コンパイル使用メモリ 77,420 KB
最終ジャッジ日時 2025-12-03 21:52:45
ジャッジサーバーID
(参考情報)
judge5 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample MLE * 1
other MLE * 8
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

def solve(s):
    numG, numR = s.count('G'), s.count('R')
    if numG != numR or numG == 0:
        return False
    stacks = []
    for light in s:
        if light == 'R':
            stacks.append(1)
        elif light == 'G':
            for i in xrange(len(stacks)):
                if stacks[i] == 1:
                    stacks[i] += 1
                    break
            else:
                return False
        else:
            if len(stacks) == 0 or max(stacks) == 1:
                return False
            for i in xrange(len(stacks)):
                if stacks[i] == 2:
                    stacks[i] += 1
                    if len(stacks) == numG and min(stacks) == 3:
                        return True
                    break
    return True

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