結果

問題 No.154 市バス
コンテスト
ユーザー tktk_snsn
提出日時 2021-02-09 20:31:39
言語 Python3
(3.14.3 + numpy 2.4.4 + scipy 1.17.1)
コンパイル:
python3 -mpy_compile _filename_
実行:
python3 _filename_
結果
WA  
実行時間 -
コード長 570 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 478 ms
コンパイル使用メモリ 20,824 KB
実行使用メモリ 15,360 KB
最終ジャッジ日時 2026-03-28 16:45:58
合計ジャッジ時間 2,187 ms
ジャッジサーバーID
(参考情報)
judge3_0 / judge2_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample WA * 1
other AC * 1 WA * 7
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)


def main():
    S = input().rstrip()
    W = 0
    G = 0
    for s in S:
        if s == "W":
            W += 1
        elif s == "G":
            if not W:
                return False
            W -= 1
            G += 1
        else:
            if not G:
                return False
            G -= 1
            if G == 0:
                W = 0
    return G == 0 and W == 0


T = int(input())
for _ in range(T):
    if main():
        print("possible")
    else:
        print("impossible")
0