結果

問題 No.154 市バス
ユーザー maspymaspy
提出日時 2020-02-28 15:53:54
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 100 ms / 2,000 ms
コード長 711 bytes
コンパイル時間 358 ms
コンパイル使用メモリ 12,672 KB
実行使用メモリ 11,776 KB
最終ジャッジ日時 2024-04-21 17:34:56
合計ジャッジ時間 2,149 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 100 ms
11,648 KB
testcase_01 AC 96 ms
11,776 KB
testcase_02 AC 97 ms
11,776 KB
testcase_03 AC 78 ms
11,520 KB
testcase_04 AC 93 ms
11,648 KB
testcase_05 AC 29 ms
10,624 KB
testcase_06 AC 29 ms
10,624 KB
testcase_07 AC 94 ms
11,648 KB
testcase_08 AC 29 ms
10,624 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