結果

問題 No.154 市バス
ユーザー 👑 rin204rin204
提出日時 2022-07-02 19:54:08
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 211 ms / 2,000 ms
コード長 589 bytes
コンパイル時間 91 ms
コンパイル使用メモリ 10,856 KB
実行使用メモリ 7,936 KB
最終ジャッジ日時 2023-08-18 11:53:08
合計ジャッジ時間 2,270 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 207 ms
7,812 KB
testcase_01 AC 208 ms
7,712 KB
testcase_02 AC 200 ms
7,712 KB
testcase_03 AC 163 ms
7,936 KB
testcase_04 AC 211 ms
7,828 KB
testcase_05 AC 15 ms
7,840 KB
testcase_06 AC 14 ms
7,712 KB
testcase_07 AC 188 ms
7,824 KB
testcase_08 AC 15 ms
7,856 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def solve():
    S = input()
    t = 0
    cnt = 0
    cnt2 = 0
    for s in S[::-1]:
        if s == "W":
            if t != 2:
                print("impossible")
                return
            cnt2 = max(cnt2 - 1, 0)
        elif s == "R":
            cnt += 1
            t = max(t, 1)
        else:
            cnt -= 1
            cnt2 += 1
            if cnt < 0:
                print("impossible")
                return
            t = 2
    if cnt2 != 0 or cnt != 0:
        print("impossible")
    else:
        print("possible")

for _ in range(int(input())):
    solve()
0