結果
| 問題 |
No.154 市バス
|
| コンテスト | |
| ユーザー |
gew1fw
|
| 提出日時 | 2025-06-12 16:07:41 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
MLE
|
| 実行時間 | - |
| コード長 | 983 bytes |
| コンパイル時間 | 204 ms |
| コンパイル使用メモリ | 82,944 KB |
| 実行使用メモリ | 76,928 KB |
| 最終ジャッジ日時 | 2025-06-12 16:07:57 |
| 合計ジャッジ時間 | 1,622 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | WA * 1 |
| other | WA * 2 MLE * 6 |
ソースコード
T = int(input())
for _ in range(T):
S = input().strip()
g_count = 0
r_count = 0
possible = True
# Check if the number of G and R are equal
g_total = S.count('G')
r_total = S.count('R')
if g_total != r_total:
print("impossible")
continue
# Check each G has at least one W before it
has_w = False
for c in S:
if c == 'W':
has_w = True
elif c == 'G':
if not has_w:
possible = False
break
if not possible:
print("impossible")
continue
# Check R's and G's order using a stack-like approach
current_g = 0
for c in S:
if c == 'G':
current_g += 1
elif c == 'R':
if current_g <= 0:
possible = False
break
current_g -= 1
if possible and current_g == 0:
print("possible")
else:
print("impossible")
gew1fw