結果

問題 No.154 市バス
ユーザー 👑 SPD_9X2
提出日時 2025-10-04 18:41:43
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
AC  
実行時間 324 ms / 2,000 ms
コード長 602 bytes
コンパイル時間 227 ms
コンパイル使用メモリ 12,160 KB
実行使用メモリ 10,240 KB
最終ジャッジ日時 2025-10-04 18:41:47
合計ジャッジ時間 3,266 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 8
権限があれば一括ダウンロードができます

ソースコード

diff #

TT = int(input())

for loop in range(TT):

    S = input()

    ans = "possible"

    a = [0,0,0]
    for v in reversed(S):
        if v == "R":
            a[0] += 1
        if v == "G":
            if a[0] == 0:
                ans = "impossible"
                break
            else:
                a[0] -= 1
                a[1] += 1
        if v == "W":
            if a[1] + a[2] == 0:
                ans = "impossible"
                break
            elif a[1] > 0:
                a[1] -= 1
                a[2] += 1

    if a[0] + a[1] != 0:
        ans = "impossible"

    print (ans)
0