結果
問題 |
No.1894 Delete AB
|
ユーザー |
|
提出日時 | 2022-04-08 21:56:22 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 609 bytes |
コンパイル時間 | 223 ms |
コンパイル使用メモリ | 82,144 KB |
実行使用メモリ | 86,244 KB |
最終ジャッジ日時 | 2024-11-28 12:36:00 |
合計ジャッジ時間 | 2,412 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | AC * 2 WA * 12 |
ソースコード
T = int(input()) for _ in range(T): N = int(input()) S = list(input()) B_count = 0 ans = [S[-1]] if S[-1] == "B": B_count+=1 A_count = 0 for i in range(-2,-(N+1),-1): if S[i] == "B": B_count+=1 ans.append("B") else: if B_count>A_count+1 and ans[-1]=="B": ans.pop() B_count-=1 if B_count == 0: A_count = 0 else: ans.append("A") if B_count >=1: A_count += 1 print("".join(reversed(ans)))