結果

問題 No.154 市バス
コンテスト
ユーザー titia
提出日時 2022-03-22 00:09:56
言語 Python3
(3.14.3 + numpy 2.4.4 + scipy 1.17.1)
コンパイル:
python3 -mpy_compile _filename_
実行:
python3 _filename_
結果
AC  
実行時間 396 ms / 2,000 ms
コード長 562 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 813 ms
コンパイル使用メモリ 20,568 KB
実行使用メモリ 15,360 KB
最終ジャッジ日時 2026-04-25 19:00:21
合計ジャッジ時間 6,891 ms
ジャッジサーバーID
(参考情報)
judge3_1 / judge2_1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 8
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

T=int(input())
for tests in range(T):
    S=input()

    W=0
    G=0
    R=0
    flag=1

    lastw=-1
    lastg=-1
    lastr=-1

    for ind in range(len(S)):
        s=S[ind]
        if s=="G":
            G+=1
            lastg=ind
        elif s=="R":
            R+=1
            lastr=ind
        else:
            W+=1
            lastw=ind
        if G<R:
            flag=0
        if W<G or W<R:
            flag=0

    if G==R and flag==1 and lastw<lastr and lastw<lastg and lastg<lastr:
        print("possible")
    else:
        print("impossible")
0