結果
問題 |
No.154 市バス
|
ユーザー |
|
提出日時 | 2016-10-05 10:35:46 |
言語 | Python2 (2.7.18) |
結果 |
AC
|
実行時間 | 244 ms / 2,000 ms |
コード長 | 700 bytes |
コンパイル時間 | 81 ms |
コンパイル使用メモリ | 7,040 KB |
実行使用メモリ | 6,400 KB |
最終ジャッジ日時 | 2024-10-13 08:44:39 |
合計ジャッジ時間 | 2,092 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | AC * 8 |
ソースコード
def solve(s): numG, numR = s.count('G'), s.count('R') if numG != numR or numG == 0: return False W, G, R = 0, 0, 0 Wassign = 0 for light in s: if light == 'R': R += 1 elif light == 'G': G += 1 Wassign += 1 else: W += 1 Wassign = max(Wassign-1, 0) if (R == 0 or G == 0) and W > 0: return False if G > R: return False if Wassign > 0: return False if G == numG and R == numR and W >= numG: return True else: return False for t in xrange(input()): print 'possible' if solve(raw_input()[::-1]) else 'impossible'