結果

問題 No.1894 Delete AB
ユーザー persimmon-persimmonpersimmon-persimmon
提出日時 2022-04-14 10:47:31
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 123 ms / 2,000 ms
コード長 493 bytes
コンパイル時間 101 ms
コンパイル使用メモリ 10,960 KB
実行使用メモリ 10,960 KB
最終ジャッジ日時 2023-08-25 19:53:22
合計ジャッジ時間 3,452 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 16 ms
7,928 KB
testcase_01 AC 113 ms
9,720 KB
testcase_02 AC 114 ms
9,724 KB
testcase_03 AC 99 ms
9,652 KB
testcase_04 AC 106 ms
9,804 KB
testcase_05 AC 112 ms
9,812 KB
testcase_06 AC 111 ms
9,572 KB
testcase_07 AC 111 ms
9,688 KB
testcase_08 AC 123 ms
9,964 KB
testcase_09 AC 59 ms
8,604 KB
testcase_10 AC 73 ms
8,604 KB
testcase_11 AC 70 ms
8,496 KB
testcase_12 AC 75 ms
8,544 KB
testcase_13 AC 110 ms
10,960 KB
testcase_14 AC 90 ms
9,676 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

t=int(input())
ns=[]
for _ in range(t):
    n=int(input())
    s=input()
    ns.append([n,s])
for n,s in ns:
    # Bの前にあるABは全て消す
    if n<=2:
        print(s)
        continue
    ans=[]
    s=list(s)
    i=0
    ans.append(s.pop())
    ans.append(s.pop())
    while s:
        if len(ans)>=2 and ans[-1]=="B" and ans[-2]=="B" and s[-1]=="A":
            s.pop()
            ans.pop()
        else:
            ans.append(s.pop())
    ans.reverse()
    print("".join(ans))
0