結果

問題 No.1894 Delete AB
ユーザー DrDrpilot
提出日時 2022-04-13 11:24:39
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
AC  
実行時間 192 ms / 2,000 ms
コード長 579 bytes
コンパイル時間 88 ms
コンパイル使用メモリ 12,288 KB
実行使用メモリ 12,524 KB
最終ジャッジ日時 2024-12-23 07:23:00
合計ジャッジ時間 3,347 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 14
権限があれば一括ダウンロードができます

ソースコード

diff #

def solve(n,s):
    ans=[]
    for i in range(n):
        if ans:
            if ans[-1]=='A' and s[i]=='B':
                if i+1<n and s[i+1]=='B':
                    ans.pop()
                    while len(ans)>=2 and ans[-2]=='A' and ans[-1]=='B':
                        ans.pop()
                        ans.pop()
                else:
                    ans.append(s[i])
            else:
                ans.append(s[i])
        else:
            ans.append(s[i])
    print(*ans,sep='')
t=int(input())
for _ in range(t):
    n=int(input())
    s=input()
    solve(n,s)
0