結果
| 問題 |
No.154 市バス
|
| コンテスト | |
| ユーザー |
lam6er
|
| 提出日時 | 2025-04-16 00:16:57 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
MLE
|
| 実行時間 | - |
| コード長 | 1,037 bytes |
| コンパイル時間 | 182 ms |
| コンパイル使用メモリ | 82,124 KB |
| 実行使用メモリ | 76,548 KB |
| 最終ジャッジ日時 | 2025-04-16 00:18:20 |
| 合計ジャッジ時間 | 1,622 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | WA * 1 |
| other | WA * 2 MLE * 6 |
ソースコード
T = int(input())
for _ in range(T):
S = input().strip()
count_g = S.count('G')
count_r = S.count('R')
if count_g != count_r:
print("impossible")
continue
possible = True
g_count = 0
r_count = 0
for c in S:
if c == 'R':
if g_count < (r_count + 1):
possible = False
break
r_count += 1
elif c == 'G':
g_count += 1
if not possible:
print("impossible")
continue
# Check each G has at least one W before it
prefix_w = [0] * (len(S) + 1)
for i in range(len(S)):
prefix_w[i+1] = prefix_w[i] + (1 if S[i] == 'W' else 0)
for i in range(len(S)):
if S[i] == 'G' and prefix_w[i] == 0:
possible = False
break
if not possible:
print("impossible")
continue
total_w = prefix_w[len(S)]
if total_w < count_g:
possible = False
print("possible" if possible else "impossible")
lam6er