結果

問題 No.154 市バス
ユーザー titia
提出日時 2022-03-22 00:09:56
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
AC  
実行時間 530 ms / 2,000 ms
コード長 562 bytes
コンパイル時間 91 ms
コンパイル使用メモリ 12,672 KB
実行使用メモリ 10,752 KB
最終ジャッジ日時 2024-10-09 15:25:03
合計ジャッジ時間 4,502 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 8
権限があれば一括ダウンロードができます

ソースコード

diff #

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