結果
| 問題 |
No.154 市バス
|
| コンテスト | |
| ユーザー |
lam6er
|
| 提出日時 | 2025-04-16 00:14:19 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
MLE
|
| 実行時間 | - |
| コード長 | 1,237 bytes |
| コンパイル時間 | 222 ms |
| コンパイル使用メモリ | 82,248 KB |
| 実行使用メモリ | 76,888 KB |
| 最終ジャッジ日時 | 2025-04-16 00:15:41 |
| 合計ジャッジ時間 | 1,667 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | WA * 1 |
| other | WA * 2 MLE * 6 |
ソースコード
T = int(input())
for _ in range(T):
s = input().strip()
possible = True
# Check first character is not R
if s[0] == 'R':
print("impossible")
continue
# Check last character is not G
if s[-1] == 'G':
print("impossible")
continue
# Precompute has_w_before array
n = len(s)
has_w_before = [False] * (n + 1)
for i in range(n):
has_w_before[i+1] = has_w_before[i] or (s[i] == 'W')
# Check each G has at least one W before it
for i in range(n):
if s[i] == 'G' and not has_w_before[i]:
possible = False
break
if not possible:
print("impossible")
continue
# Check count of G and R are equal
count_g = s.count('G')
count_r = s.count('R')
if count_g != count_r:
print("impossible")
continue
# Check balance during processing
balance = 0
for c in s:
if c == 'G':
balance += 1
elif c == 'R':
balance -= 1
if balance < 0:
possible = False
break
if possible and balance == 0:
print("possible")
else:
print("impossible")
lam6er