結果

問題 No.154 市バス
ユーザー kimiyukikimiyuki
提出日時 2016-10-22 12:08:38
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 106 ms / 2,000 ms
コード長 583 bytes
コンパイル時間 294 ms
コンパイル使用メモリ 12,544 KB
実行使用メモリ 10,752 KB
最終ジャッジ日時 2024-04-21 09:58:58
合計ジャッジ時間 1,395 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 99 ms
10,624 KB
testcase_01 AC 103 ms
10,624 KB
testcase_02 AC 106 ms
10,752 KB
testcase_03 AC 80 ms
10,752 KB
testcase_04 AC 97 ms
10,752 KB
testcase_05 AC 29 ms
10,624 KB
testcase_06 AC 28 ms
10,752 KB
testcase_07 AC 105 ms
10,624 KB
testcase_08 AC 29 ms
10,752 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