結果

問題 No.154 市バス
ユーザー nebukuro09nebukuro09
提出日時 2016-10-05 10:20:10
言語 PyPy2
(7.3.15)
結果
MLE  
実行時間 -
コード長 860 bytes
コンパイル時間 420 ms
コンパイル使用メモリ 76,928 KB
実行使用メモリ 78,720 KB
最終ジャッジ日時 2024-04-21 09:57:12
合計ジャッジ時間 4,333 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 MLE -
testcase_01 MLE -
testcase_02 MLE -
testcase_03 MLE -
testcase_04 MLE -
testcase_05 MLE -
testcase_06 MLE -
testcase_07 MLE -
testcase_08 MLE -
権限があれば一括ダウンロードができます

ソースコード

diff #

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