結果
| 問題 |
No.154 市バス
|
| コンテスト | |
| ユーザー |
gew1fw
|
| 提出日時 | 2025-06-12 20:51:58 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
MLE
|
| 実行時間 | - |
| コード長 | 910 bytes |
| コンパイル時間 | 345 ms |
| コンパイル使用メモリ | 82,244 KB |
| 実行使用メモリ | 76,668 KB |
| 最終ジャッジ日時 | 2025-06-12 20:56:17 |
| 合計ジャッジ時間 | 1,868 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | WA * 1 |
| other | WA * 2 MLE * 6 |
ソースコード
def is_possible(s):
g_count = s.count('G')
r_count = s.count('R')
if g_count != r_count:
return False
w_count = s.count('W')
if w_count < g_count:
return False
# Check each G has at least one W before it
n = len(s)
prefix_w = [0] * (n + 1)
for i in range(n):
prefix_w[i+1] = prefix_w[i] + (1 if s[i] == 'W' else 0)
for i in range(n):
if s[i] == 'G' and prefix_w[i] == 0:
return False
# Check R count never exceeds G count during processing
current_g = 0
current_r = 0
for c in s:
if c == 'G':
current_g += 1
elif c == 'R':
current_r += 1
if current_r > current_g:
return False
return True
T = int(input())
for _ in range(T):
S = input().strip()
if is_possible(S):
print("possible")
else:
print("impossible")
gew1fw