結果

問題 No.154 市バス
ユーザー tktk_snsntktk_snsn
提出日時 2021-02-09 20:56:11
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 120 ms / 2,000 ms
コード長 730 bytes
コンパイル時間 120 ms
コンパイル使用メモリ 10,848 KB
実行使用メモリ 8,308 KB
最終ジャッジ日時 2023-09-21 08:39:39
合計ジャッジ時間 1,806 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 119 ms
8,160 KB
testcase_01 AC 120 ms
8,300 KB
testcase_02 AC 118 ms
8,236 KB
testcase_03 AC 77 ms
8,308 KB
testcase_04 AC 117 ms
8,156 KB
testcase_05 AC 16 ms
7,956 KB
testcase_06 AC 16 ms
7,856 KB
testcase_07 AC 100 ms
8,224 KB
testcase_08 AC 15 ms
7,860 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)


def main():
    S = input().rstrip()[::-1]
    R = 0
    st = []
    for s in S:
        if s == "R":
            R += 1
        elif s == "G":
            if not R:
                return False
            R -= 1
            st.append(1)
        else:
            if not st:
                return False
            st.append(0)
    if R:
        return False
    st.reverse()
    W = 0
    for s in st:
        if s == 0:
            W += 1
        else:
            if not W:
                return False
            W -= 1
    return True


T = int(input())
for _ in range(T):
    if main():
        print("possible")
    else:
        print("impossible")
0