結果

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

ソースコード

diff #

from collections import deque

t = int(input())
for _ in range(t):
    n = int(input())
    S = input()
    ANS = deque()
    for i in range(n - 1, -1, -1):
        ANS.appendleft(S[i])
        if len(ANS) > 1 and ANS[0] == 'A' and ANS[1] == 'B':
            if len(ANS) > 2 and ANS[2] == 'B':
                ANS.popleft()
                ANS.popleft()
    print(''.join(ANS))
0