結果
問題 |
No.154 市バス
|
ユーザー |
![]() |
提出日時 | 2025-04-16 00:17:48 |
言語 | PyPy3 (7.3.15) |
結果 |
MLE
|
実行時間 | - |
コード長 | 1,237 bytes |
コンパイル時間 | 429 ms |
コンパイル使用メモリ | 82,512 KB |
実行使用メモリ | 76,772 KB |
最終ジャッジ日時 | 2025-04-16 00:19:34 |
合計ジャッジ時間 | 1,790 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
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")