結果

問題 No.154 市バス
ユーザー Navier_BoltzmannNavier_Boltzmann
提出日時 2023-01-21 17:46:19
言語 PyPy3
(7.3.15)
結果
MLE  
実行時間 -
コード長 893 bytes
コンパイル時間 273 ms
コンパイル使用メモリ 87,336 KB
実行使用メモリ 79,868 KB
最終ジャッジ日時 2023-09-06 06:13:34
合計ジャッジ時間 3,170 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 MLE -
testcase_01 MLE -
testcase_02 MLE -
testcase_03 MLE -
testcase_04 MLE -
testcase_05 MLE -
testcase_06 MLE -
testcase_07 MLE -
testcase_08 MLE -
権限があれば一括ダウンロードができます

ソースコード

diff #

def answer():
    S = list(input())
    W = [int(i == 'W') for i in S]
    G = [int(i == 'G') for i in S]
    R = [int(i == 'R') for i in S]
    N = len(S)
    from itertools import accumulate
    
    SW = list(accumulate(W))
    SG = list(accumulate(G))
    SR = list(accumulate(R))
    for i in range(N):
        if SW[i]>=SG[i]>=SR[i]:
            continue
        else:
            print('impossible')
            return
    
    if SG[-1] != SR[-1]:
        print('impossible')
        return
    LG = N
    LR = N
    for i in range(N-1,-1,-1):
        if S[i]=='R':
            LR = i
            break
    for i in range(N-1,-1,-1):
        if S[i]=='G':
            LG = i
            break
    if LR<LG:
        print('impossible')
        return
    if LR!=N-1:
        print('impossible')
        return
    print('possible')
    return

for _ in range(int(input())):
    answer()
0