結果

問題 No.154 市バス
ユーザー lloyz
提出日時 2023-06-15 00:47:46
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
AC  
実行時間 375 ms / 2,000 ms
コード長 509 bytes
コンパイル時間 112 ms
コンパイル使用メモリ 12,672 KB
実行使用メモリ 10,880 KB
最終ジャッジ日時 2024-06-23 05:23:10
合計ジャッジ時間 3,117 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 8
権限があれば一括ダウンロードができます

ソースコード

diff #

for _ in range(int(input())):
    s = input()
    n = len(s)
    r = 0
    g = 0
    GR = False
    for i in range(n - 1, -1, -1):
        if s[i] == 'R':
            r += 1
        elif s[i] == 'G':
            r -= 1
            if r == -1:
                break
            GR = True
            g += 1
        else:
            if not GR:
                break
            if g > 0:
                g -= 1
    if r != 0 or g != 0 or not GR:
        print("impossible")
    else:
        print("possible")
0