結果
問題 | 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 FalseW, G, R = 0, 0, 0Wassign = 0for light in s:if light == 'R':R += 1elif light == 'G':G += 1Wassign += 1else:W += 1Wassign = max(Wassign-1, 0)if (R == 0 or G == 0) and W > 0:return Falseif G > R:return Falseif Wassign > 0:return Falseif G == numG and R == numR and W >= numG:return Trueelse:return Falsefor t in xrange(input()):print 'possible' if solve(raw_input()[::-1]) else 'impossible'