結果

問題 No.1894 Delete AB
ユーザー 👑 H20H20
提出日時 2022-04-08 21:54:06
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 163 ms / 2,000 ms
コード長 458 bytes
コンパイル時間 308 ms
コンパイル使用メモリ 82,688 KB
実行使用メモリ 87,552 KB
最終ジャッジ日時 2024-05-06 07:28:24
合計ジャッジ時間 2,606 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 42 ms
53,760 KB
testcase_01 AC 98 ms
87,168 KB
testcase_02 AC 92 ms
87,040 KB
testcase_03 AC 131 ms
77,604 KB
testcase_04 AC 163 ms
77,596 KB
testcase_05 AC 130 ms
76,800 KB
testcase_06 AC 155 ms
77,696 KB
testcase_07 AC 150 ms
78,080 KB
testcase_08 AC 158 ms
77,952 KB
testcase_09 AC 118 ms
77,056 KB
testcase_10 AC 111 ms
77,440 KB
testcase_11 AC 99 ms
77,184 KB
testcase_12 AC 106 ms
79,104 KB
testcase_13 AC 92 ms
87,552 KB
testcase_14 AC 82 ms
86,912 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import collections
T = int(input())
for _ in range(T):
    N=int(input())
    S = list(input())
    d = collections.deque()
    d.append('x')
    d.append('x')
    bcnt = 0
    for s in S[::-1]:
        d.append(s)
        if d[-1]=='B' and d[-2]=='B':
            bcnt+=1
        while d[-1]=='A' and d[-2]=='B' and bcnt>=1:
            d.pop()
            d.pop()
            bcnt-=1

    ANS = list(d)[::-1]
    print(''.join(map(str, ANS[:len(ANS)-2])))
0