結果

問題 No.154 市バス
ユーザー HachimoriHachimori
提出日時 2015-02-18 00:37:21
言語 Python2
(2.7.18)
結果
AC  
実行時間 442 ms / 2,000 ms
コード長 817 bytes
コンパイル時間 128 ms
コンパイル使用メモリ 6,508 KB
実行使用メモリ 6,360 KB
最終ジャッジ日時 2023-08-03 09:13:39
合計ジャッジ時間 3,692 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 440 ms
6,156 KB
testcase_01 AC 442 ms
6,360 KB
testcase_02 AC 429 ms
6,156 KB
testcase_03 AC 268 ms
6,228 KB
testcase_04 AC 419 ms
6,264 KB
testcase_05 AC 10 ms
6,044 KB
testcase_06 AC 9 ms
6,124 KB
testcase_07 AC 386 ms
6,088 KB
testcase_08 AC 9 ms
6,052 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#!/usr/bin/env python
#coding:utf8


def read():
    return raw_input()


def work(s):
    chList = "WGR"

    val = [0, 0, 0]
    for ch in s:
        val[chList.find(ch)] += 1
        if not (val[0] >= val[1] >= val[2]):
            print "impossible"
            return

    wIdx = []
    gIdx = []
    for idx, ch in enumerate(s):
        if ch == 'W':
            wIdx.append(idx)
        if ch == 'G':
            gIdx.append(idx)

    for idx in wIdx:
        while gIdx and idx > gIdx[0]:
            del gIdx[0]
        if not gIdx:
            print "impossible"
            return
    
    if val[0] >= val[1] and val[1] == val[2] and val[2] > 0 and s[-1] == 'R':
        print "possible" 
    else:
        print "impossible"


if __name__ == "__main__":
    for i in range(input()):
        work(read())
0