結果

問題 No.154 市バス
ユーザー ronpoo
提出日時 2023-08-29 09:46:39
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
AC  
実行時間 579 ms / 2,000 ms
コード長 652 bytes
コンパイル時間 153 ms
コンパイル使用メモリ 12,672 KB
実行使用メモリ 10,880 KB
最終ジャッジ日時 2024-12-30 23:08:47
合計ジャッジ時間 4,463 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 8
権限があれば一括ダウンロードができます

ソースコード

diff #

T = int(input())

for i in range(T):
    s = input()    
    L = len(s)
    wg = 0
    gr = 0
    f = True
    for i in range(L):
        if s[i] == 'W' :
            wg += 1
        elif s[i] == 'G':
            wg -= 1
            gr += 1
        elif s[i] == 'R':
            gr -= 1
        if  not(0 <= gr and 0 <= wg):
            print('impossible')      
            break
        
        if s[L-i-1] == 'G':
            f = False
        if f and s[L-i-1] == 'W':
            print('impossible')      
            break
    else:
        if gr == 0:
            print('possible')
        else:
            print('impossible')    
            
0