結果
| 問題 | No.154 市バス |
| コンテスト | |
| ユーザー |
gew1fw
|
| 提出日時 | 2025-06-12 20:49:23 |
| 言語 | PyPy3 (7.3.17) |
| 結果 |
MLE
|
| 実行時間 | - |
| コード長 | 983 bytes |
| 記録 | |
| コンパイル時間 | 238 ms |
| コンパイル使用メモリ | 95,728 KB |
| 実行使用メモリ | 84,864 KB |
| 最終ジャッジ日時 | 2026-07-12 01:35:00 |
| 合計ジャッジ時間 | 2,242 ms |
|
ジャッジサーバーID (参考情報) |
judge1_1 / judge3_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | MLE * 1 |
| other | MLE * 8 |
ソースコード
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