結果

問題 No.154 市バス
コンテスト
ユーザー はむ吉🐹
提出日時 2016-02-13 19:02:34
言語 Python3
(3.14.7 + numpy 2.5.2 + scipy 1.18.0 + ACL)
コンパイル:
python3 -mpy_compile _filename_
実行:
python3 _filename_
結果
AC  
実行時間 305 ms / 2,000 ms
+ 776µs
コード長 768 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 56 ms
コンパイル使用メモリ 14,976 KB
実行使用メモリ 10,880 KB
最終ジャッジ日時 2026-09-15 12:49:36
合計ジャッジ時間 2,986 ms
ジャッジサーバーID
(参考情報)
judge2_0 / judge3_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 8
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import collections

W = "W"
G = "G"
R = "R"


def solve(memo):
    counter = collections.Counter()
    for light in memo[::-1]:
        if light == R:
            counter[R] += 1
        elif light == G:
            counter[R] -= 1
            counter[G] += 1
            if counter[R] < 0:
                return False
        elif light == W:
            if counter[G] > 0:
                counter[G] -= 1
                counter[W] += 1
            elif counter[W] == 0:
                return False
    return counter[R] == counter[G] == 0


if __name__ == "__main__":
    t = int(input())
    for i in range(t):
        if solve(input()):
            print("possible")
        else:
            print("impossible")
0