結果

問題 No.154 市バス
ユーザー maspymaspy
提出日時 2020-02-28 15:53:54
言語 Python3
(3.11.6 + numpy 1.26.0 + scipy 1.11.3)
結果
AC  
実行時間 77 ms / 2,000 ms
コード長 711 bytes
コンパイル時間 274 ms
コンパイル使用メモリ 10,984 KB
実行使用メモリ 9,136 KB
最終ジャッジ日時 2023-08-03 19:19:23
合計ジャッジ時間 1,624 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 75 ms
9,136 KB
testcase_01 AC 75 ms
9,028 KB
testcase_02 AC 74 ms
9,084 KB
testcase_03 AC 59 ms
8,996 KB
testcase_04 AC 70 ms
9,120 KB
testcase_05 AC 16 ms
7,824 KB
testcase_06 AC 15 ms
7,792 KB
testcase_07 AC 77 ms
9,024 KB
testcase_08 AC 16 ms
7,808 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#!/usr/bin/env python3
# %%
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines


# %%
T = int(readline())
query = readlines()

# %%


def solve(q):
    w_min = 0
    w_max = 0
    g = 0
    for a in q.rstrip().decode():
        if a == 'W':
            w_min = 1
            w_max += 1
        elif a == 'G':
            if not w_max:
                return False
            w_min = 0
            w_max -= 1
            g += 1
        else:
            if not g:
                return False
            g -= 1
    return w_min == 0 and g == 0


# %%
answers = ('possible' if solve(q) else 'impossible' for q in query)
print('\n'.join(answers))
0