結果

問題 No.154 市バス
ユーザー steek79steek79
提出日時 2015-10-14 16:46:52
言語 Python2
(2.7.18)
結果
AC  
実行時間 191 ms / 2,000 ms
コード長 930 bytes
コンパイル時間 59 ms
コンパイル使用メモリ 6,940 KB
実行使用メモリ 6,400 KB
最終ジャッジ日時 2024-04-21 08:50:32
合計ジャッジ時間 1,958 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 174 ms
6,400 KB
testcase_01 AC 171 ms
6,400 KB
testcase_02 AC 173 ms
6,400 KB
testcase_03 AC 156 ms
6,400 KB
testcase_04 AC 159 ms
6,272 KB
testcase_05 AC 10 ms
6,400 KB
testcase_06 AC 11 ms
6,400 KB
testcase_07 AC 191 ms
6,400 KB
testcase_08 AC 11 ms
6,400 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#!/usr/bin/python
# -*- coding: utf-8 -*-

# よくわかんなくなった
# pekempey さんのをカンニングした

def check(str):
    W = R = 0
    hasW = hasR = hasG = False
    
    for s in str:
        if s == 'W':
            W += 1
        elif s == 'G':
            W -= 1
        
        if W < 0: return False #前から見て白より多く緑が出たらだめ
        
    for s in str[::-1]:
        if s == 'W':
            if not hasG: return False #後ろから見て緑がないのに白があったらだめ
        elif s == 'G':
            hasG = True
            R -= 1
        elif s == 'R':
            R += 1
        if R < 0 : return False #後ろから見て赤より多く緑が出たらだめ
    
    return R == 0 # ?

#条件それだけなのか

T = input()
for t in range(T):
    inp = raw_input()
    if check(inp) == True:
        print 'possible'
    else:
        print 'impossible'
0