結果

問題 No.154 市バス
ユーザー ronpooronpoo
提出日時 2023-08-29 09:46:39
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 510 ms / 2,000 ms
コード長 652 bytes
コンパイル時間 282 ms
コンパイル使用メモリ 10,884 KB
実行使用メモリ 7,896 KB
最終ジャッジ日時 2023-08-29 09:46:43
合計ジャッジ時間 4,269 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 450 ms
7,764 KB
testcase_01 AC 477 ms
7,860 KB
testcase_02 AC 455 ms
7,760 KB
testcase_03 AC 329 ms
7,784 KB
testcase_04 AC 418 ms
7,896 KB
testcase_05 AC 15 ms
7,820 KB
testcase_06 AC 15 ms
7,764 KB
testcase_07 AC 510 ms
7,840 KB
testcase_08 AC 14 ms
7,840 KB
権限があれば一括ダウンロードができます

ソースコード

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