結果

問題 No.154 市バス
ユーザー kichirb3kichirb3
提出日時 2018-04-02 08:09:57
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 847 bytes
コンパイル時間 99 ms
コンパイル使用メモリ 10,996 KB
実行使用メモリ 8,392 KB
最終ジャッジ日時 2023-09-08 13:18:08
合計ジャッジ時間 1,751 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 81 ms
8,348 KB
testcase_01 AC 79 ms
8,296 KB
testcase_02 AC 78 ms
8,260 KB
testcase_03 AC 64 ms
8,252 KB
testcase_04 AC 74 ms
8,392 KB
testcase_05 WA -
testcase_06 WA -
testcase_07 AC 111 ms
8,180 KB
testcase_08 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

# -*- coding: utf-8 -*-
"""
No.154 市バス
https://yukicoder.me/problems/no/154

"""
import sys
from sys import stdin
input = stdin.readline


def solve(S):
    G_stack = []
    W_stack = []

    for s in S:
        if s == 'W':
            W_stack.append(1)
        elif s == 'G':
            if len(W_stack) == 0:
                return 'impossible'
            else:
                _ = W_stack.pop()
                G_stack.append(1)
        elif s == 'R':
            if len(G_stack) == 0:
                return 'impossible'
            else:
                _ = G_stack.pop()

    if len(G_stack) != 0:
        return 'impossible'
    return 'possible'



def main(args):
    T = int(input())
    for _ in range(T):
        S = input().strip()
        ans = solve(S)
        print(ans)


if __name__ == '__main__':
    main(sys.argv[1:])
0