結果

問題 No.1894 Delete AB
ユーザー DrDrpilotDrDrpilot
提出日時 2022-04-13 11:24:39
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 153 ms / 2,000 ms
コード長 579 bytes
コンパイル時間 164 ms
コンパイル使用メモリ 11,000 KB
実行使用メモリ 10,108 KB
最終ジャッジ日時 2023-08-24 21:20:20
合計ジャッジ時間 3,302 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 16 ms
7,940 KB
testcase_01 AC 69 ms
8,504 KB
testcase_02 AC 69 ms
8,660 KB
testcase_03 AC 129 ms
7,924 KB
testcase_04 AC 137 ms
7,912 KB
testcase_05 AC 140 ms
7,820 KB
testcase_06 AC 141 ms
7,764 KB
testcase_07 AC 144 ms
7,916 KB
testcase_08 AC 153 ms
7,792 KB
testcase_09 AC 56 ms
8,288 KB
testcase_10 AC 67 ms
8,136 KB
testcase_11 AC 59 ms
8,220 KB
testcase_12 AC 58 ms
8,328 KB
testcase_13 AC 66 ms
9,372 KB
testcase_14 AC 68 ms
10,108 KB
権限があれば一括ダウンロードができます

ソースコード

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