結果

問題 No.154 市バス
ユーザー kimiyukikimiyuki
提出日時 2016-10-22 12:08:38
言語 Python3
(3.11.6 + numpy 1.26.0 + scipy 1.11.3)
結果
AC  
実行時間 89 ms / 2,000 ms
コード長 583 bytes
コンパイル時間 129 ms
コンパイル使用メモリ 10,856 KB
実行使用メモリ 7,952 KB
最終ジャッジ日時 2023-08-03 12:03:43
合計ジャッジ時間 1,465 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 82 ms
7,780 KB
testcase_01 AC 80 ms
7,952 KB
testcase_02 AC 82 ms
7,828 KB
testcase_03 AC 65 ms
7,868 KB
testcase_04 AC 81 ms
7,852 KB
testcase_05 AC 16 ms
7,816 KB
testcase_06 AC 16 ms
7,896 KB
testcase_07 AC 89 ms
7,816 KB
testcase_08 AC 16 ms
7,812 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#!/usr/bin/env python3
def is_possible(s):
    w0 = 0
    w1 = False
    g = 0
    r = 0
    for c in s:
        if c == 'W':
            w0 += 1
            w1 = True
        elif c == 'G':
            if not w0:
                return False
            w1 = False
            w0 -= 1
            g  += 1
        elif c == 'R':
            if not g:
                return False
            g -= 1
            r += 1
    if w1 or g:
        return False
    return True


t = int(input())
for _ in range(t):
    s = input()
    print('possible' if is_possible(s) else 'impossible')
0