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