結果

問題 No.154 市バス
コンテスト
ユーザー lloyz
提出日時 2023-06-15 00:47:46
言語 Python3
(3.14.7 + numpy 2.5.2 + scipy 1.18.0 + ACL)
コンパイル:
python3 -mpy_compile _filename_
実行:
python3 _filename_
結果
AC  
実行時間 189 ms / 2,000 ms
+ 447µs
コード長 509 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 57 ms
コンパイル使用メモリ 14,976 KB
実行使用メモリ 11,008 KB
最終ジャッジ日時 2026-10-12 17:20:44
合計ジャッジ時間 2,784 ms
ジャッジサーバーID
(参考情報)
judge3_0 / judge2_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 9
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

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