結果

問題 No.154 市バス
ユーザー norioc
提出日時 2025-02-20 03:27:58
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
AC  
実行時間 496 ms / 2,000 ms
コード長 698 bytes
コンパイル時間 175 ms
コンパイル使用メモリ 12,160 KB
実行使用メモリ 10,368 KB
最終ジャッジ日時 2025-02-20 03:28:02
合計ジャッジ時間 3,493 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 8
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import Counter


def solve(s: str) -> bool:
    if s[-1] != 'R': return False

    t = Counter()
    used_g = False
    for c in reversed(s):
        match c:
            case 'W':
                if not used_g: return False
                if t['G'] > 0:
                    t['G'] -= 1
            case 'G':
                if t['R'] == 0: return False
                used_g = True
                t['R'] -= 1
                t['G'] += 1
            case 'R':
                t['R'] += 1

    if t['R'] or t['G']: return False
    return True


T = int(input())
for _ in range(T):
    S = input()
    if solve(S):
        print('possible')
    else:
        print('impossible')
0