結果
問題 |
No.154 市バス
|
ユーザー |
![]() |
提出日時 | 2025-06-12 21:19:25 |
言語 | PyPy3 (7.3.15) |
結果 |
MLE
|
実行時間 | - |
コード長 | 1,243 bytes |
コンパイル時間 | 160 ms |
コンパイル使用メモリ | 81,736 KB |
実行使用メモリ | 76,652 KB |
最終ジャッジ日時 | 2025-06-12 21:19:44 |
合計ジャッジ時間 | 1,516 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
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 # Check each G has an R after it for i in range(len(s)): if s[i] == 'G': found_r = False for j in range(i+1, len(s)): if s[j] == 'R': found_r = True break if not found_r: return False # Check Ws before each G for i in range(len(s)): if s[i] == 'G': # Find the last R before i last_r = -1 for j in range(i-1, -1, -1): if s[j] == 'R': last_r = j break # Determine the start of the segment start = 0 if last_r == -1 else last_r + 1 end = i - 1 # Count Ws in this segment w_count = 0 for k in range(start, end + 1): if s[k] == 'W': w_count += 1 if w_count < 1: return False return True T = int(input()) for _ in range(T): S = input().strip() if is_possible(S): print("possible") else: print("impossible")