結果

問題 No.154 市バス
ユーザー mnr
提出日時 2020-03-02 23:47:31
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
WA  
実行時間 -
コード長 1,399 bytes
コンパイル時間 125 ms
コンパイル使用メモリ 12,544 KB
実行使用メモリ 18,688 KB
最終ジャッジ日時 2024-10-13 21:24:43
合計ジャッジ時間 3,938 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 7 WA * 1
権限があれば一括ダウンロードができます

ソースコード

diff #

def judge(list):
    cnt_r = 0
    cnt_g = 0
    cnt_w = 0
    pori = True
    for i in range(1,len(list)+1):
        if list[-i] == 'R':
            cnt_r += 1
        if list[-i] == 'G':
            cnt_g += 1
        if list[-i] == 'W':
            cnt_w += 1
            
        if cnt_g > cnt_r:
            pori = False
            break
        if cnt_g == 0 and cnt_w != 0:
            pori = False
            break
        if cnt_r == 0 and cnt_w != 0:
            pori = False
            break

    if cnt_g != cnt_r:
        pori = False
    if cnt_w < cnt_g or cnt_w < cnt_r:
        pori = False

    if pori:
        cnt2_r = 0
        cnt2_g = 0
        cnt2_w = 0
        for i in range(len(list)):
            if list[i] == 'R':
                cnt2_r += 1
            if list[i] == 'G':
                cnt2_g += 1
            if list[i] == 'W':
                cnt2_w += 1

            if cnt2_r > cnt2_g:
                pori = False
                break
            if cnt2_w == 0 and cnt2_g != 0:
                pori = False
                break
            if cnt2_w == 0 and cnt2_r != 0:
                pori = False
                break
            
    if pori == True:
        print("possible")
    if pori == False:
        print("impossible")
    
T = int(input())
L = []
for i in range(T):
    S = input()
    L.append(list(S))
for i in range(T):
    judge(L[i])
0