結果

問題 No.154 市バス
ユーザー phtmscgphtmscg
提出日時 2019-05-14 19:13:47
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 583 ms / 2,000 ms
コード長 862 bytes
コンパイル時間 96 ms
コンパイル使用メモリ 10,820 KB
実行使用メモリ 8,288 KB
最終ジャッジ日時 2023-09-26 10:49:52
合計ジャッジ時間 4,733 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 583 ms
8,224 KB
testcase_01 AC 577 ms
8,192 KB
testcase_02 AC 582 ms
8,196 KB
testcase_03 AC 159 ms
8,288 KB
testcase_04 AC 566 ms
8,288 KB
testcase_05 AC 15 ms
7,764 KB
testcase_06 AC 16 ms
7,724 KB
testcase_07 AC 536 ms
8,272 KB
testcase_08 AC 16 ms
7,724 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

N = int(input())
for _ in range(N):
    C = input()[::-1]
    cr,cg,cw = C.count("R"),C.count("G"),C.count("W")
    if cr == cg and cw >= cr:
        QR = [0,0]
        QG = [0,0]
        while C:
            color = C[0]
            C = C[1:]
            if color == "R":
                QR[0] += 1
            elif color == "G" and QR[0]>QG[0]:
                QG[0] += 1
            elif color == "G":
                print("impossible")
                break
            elif QR[0]*QG[0]==0 and color == "W":
                print("impossible")
                break
            elif QR[0]>QR[1] and QG[0]>QG[1]:
                QR[1] += 1
                QG[1] += 1
        else:
            if QR[0]-QR[1] == 0 and QG[0]-QG[1]==0:
                print("possible")
            else:
                print("impossible")
    else:
        print("impossible")
0