結果

問題 No.1894 Delete AB
ユーザー HydruHydru
提出日時 2022-04-08 22:22:19
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 151 ms / 2,000 ms
コード長 499 bytes
コンパイル時間 527 ms
コンパイル使用メモリ 82,176 KB
実行使用メモリ 77,696 KB
最終ジャッジ日時 2024-11-28 13:05:23
合計ジャッジ時間 2,462 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 14
権限があれば一括ダウンロードができます

ソースコード

diff #

T = int(input())
for _ in range(T):
    N = int(input())
    S = list(input())
    ans = [S[-1]]
    B_count = 0
    if S[-1]=="B":
        B_count+=1
    for i in range(-2,-(N+1),-1):
        if S[i] == "B":
            B_count+=1
            ans.append("B")
        else:
            if B_count>=2 and ans[-1]=="B":
                ans.pop()
                B_count-=1
            else:
                B_count = 0
                ans.append("A")
                
    print("".join(reversed(ans)))
0