結果

問題 No.154 市バス
ユーザー gew1fw
提出日時 2025-06-12 20:47:18
言語 PyPy3
(7.3.15)
結果
MLE  
実行時間 -
コード長 838 bytes
コンパイル時間 154 ms
コンパイル使用メモリ 82,140 KB
実行使用メモリ 76,388 KB
最終ジャッジ日時 2025-06-12 20:48:23
合計ジャッジ時間 1,552 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample WA * 1
other WA * 2 MLE * 6
権限があれば一括ダウンロードができます

ソースコード

diff #

T = int(input())
for _ in range(T):
    S = input().strip()
    count_G = S.count('G')
    count_R = S.count('R')
    count_W = S.count('W')
    
    if count_G != count_R:
        print("impossible")
        continue
    if count_W < count_G:
        print("impossible")
        continue
    
    available_W = 0
    available_G = 0
    possible = True
    
    for c in S:
        if c == 'W':
            available_W += 1
        elif c == 'G':
            if available_W < 1:
                possible = False
                break
            available_W -= 1
            available_G += 1
        elif c == 'R':
            if available_G < 1:
                possible = False
                break
            available_G -= 1
    
    if possible and available_G == 0:
        print("possible")
    else:
        print("impossible")
0