結果

問題 No.1894 Delete AB
ユーザー ikoma
提出日時 2022-04-08 21:45:49
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 112 ms / 2,000 ms
コード長 391 bytes
コンパイル時間 483 ms
コンパイル使用メモリ 82,416 KB
実行使用メモリ 91,016 KB
最終ジャッジ日時 2024-11-28 12:25:16
合計ジャッジ時間 2,294 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 14
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = sys.stdin.readline

T=int(input())
for t in range(T):
    N=int(input())
    S=input().strip()
    stack = []
    for s in S:
        if s=="B":
            while len(stack)>=2:
                if stack[-2]=="A" and stack[-1]=="B":
                    stack.pop()
                    stack.pop()
                else:break
        stack.append(s)
    print("".join(stack))
0