結果
問題 |
No.154 市バス
|
ユーザー |
![]() |
提出日時 | 2025-06-12 16:08:58 |
言語 | PyPy3 (7.3.15) |
結果 |
MLE
|
実行時間 | - |
コード長 | 910 bytes |
コンパイル時間 | 452 ms |
コンパイル使用メモリ | 82,768 KB |
実行使用メモリ | 76,792 KB |
最終ジャッジ日時 | 2025-06-12 16:09:01 |
合計ジャッジ時間 | 2,044 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
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")