結果

問題 No.154 市バス
ユーザー H3PO4H3PO4
提出日時 2020-05-07 00:18:28
言語 Python3
(3.11.6 + numpy 1.26.0 + scipy 1.11.3)
結果
AC  
実行時間 82 ms / 2,000 ms
コード長 505 bytes
コンパイル時間 101 ms
コンパイル使用メモリ 10,728 KB
実行使用メモリ 7,976 KB
最終ジャッジ日時 2023-09-16 07:37:48
合計ジャッジ時間 1,336 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 81 ms
7,836 KB
testcase_01 AC 80 ms
7,876 KB
testcase_02 AC 79 ms
7,868 KB
testcase_03 AC 63 ms
7,800 KB
testcase_04 AC 75 ms
7,900 KB
testcase_05 AC 15 ms
7,872 KB
testcase_06 AC 15 ms
7,864 KB
testcase_07 AC 82 ms
7,924 KB
testcase_08 AC 15 ms
7,976 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def solve(S):
    wg, gr = 0, 0
    w_flag = True
    for s in S:
        if s == 'W':
            wg += 1
            w_flag = False
        elif s == 'G':
            if not wg:
                return False
            w_flag = True
            wg -= 1
            gr += 1
        elif s == 'R':
            if not gr:
                return False
            gr -= 1
    return w_flag and not gr


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