結果

問題 No.154 市バス
コンテスト
ユーザー cologne
提出日時 2025-12-11 13:06:44
言語 Python3
(3.14.3 + numpy 2.4.4 + scipy 1.17.1)
コンパイル:
python3 -mpy_compile _filename_
実行:
python3 _filename_
結果
WA  
実行時間 -
コード長 685 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 314 ms
コンパイル使用メモリ 21,412 KB
実行使用メモリ 15,744 KB
最終ジャッジ日時 2026-07-19 09:39:12
合計ジャッジ時間 3,590 ms
ジャッジサーバーID
(参考情報)
judge1_0 / judge3_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample WA * 1
other AC * 6 WA * 2
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

import sys


def input(): return sys.stdin.readline().rstrip('\n')


def main():
    def solve(x):
        r = g = 0
        for c in x:
            if c == 'R':
                r += 1
            elif c == 'G':
                if r == 0:
                    return False
                else:
                    r -= 1
                    g += 1
            elif c == 'W':
                g = max(0, g - 1)
            else:
                assert False
        return r == g == 0

    t = int(input())
    for _ in range(t):
        print('possible' if solve(input()[::-1]) else 'impossible')


if __name__ == '__main__':
    ret = main()
    if ret is not None:
        print(ret)
0