結果

問題 No.1894 Delete AB
ユーザー kohei2019
提出日時 2023-07-13 22:36:00
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 133 ms / 2,000 ms
コード長 426 bytes
コンパイル時間 279 ms
コンパイル使用メモリ 82,168 KB
実行使用メモリ 77,056 KB
最終ジャッジ日時 2024-09-15 08:25:17
合計ジャッジ時間 2,587 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 14
権限があれば一括ダウンロードができます

ソースコード

diff #

T = int(input())
ansls = []
for i in range(T):
    n = int(input())
    S = input()
    ans = []
    cntB = 0
    for j in range(n-1,-1,-1):
        if S[j] == 'B':
            cntB += 1
            ans.append('B')
        elif cntB > 1:
            cntB -= 1
            ans.pop()
        else:
            cntB = 0
            ans.append('A')
    ans.reverse()
    ansls.append(''.join(ans))
for ans in ansls:
    print(ans)
0