結果

問題 No.1894 Delete AB
ユーザー 👑 H20H20
提出日時 2022-04-08 21:54:06
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 190 ms / 2,000 ms
コード長 458 bytes
コンパイル時間 263 ms
コンパイル使用メモリ 87,184 KB
実行使用メモリ 89,084 KB
最終ジャッジ日時 2023-08-19 00:31:41
合計ジャッジ時間 3,207 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 81 ms
71,624 KB
testcase_01 AC 127 ms
89,084 KB
testcase_02 AC 123 ms
88,500 KB
testcase_03 AC 158 ms
78,868 KB
testcase_04 AC 180 ms
79,768 KB
testcase_05 AC 151 ms
78,532 KB
testcase_06 AC 185 ms
79,920 KB
testcase_07 AC 169 ms
78,788 KB
testcase_08 AC 190 ms
78,772 KB
testcase_09 AC 149 ms
79,668 KB
testcase_10 AC 138 ms
80,020 KB
testcase_11 AC 125 ms
78,580 KB
testcase_12 AC 123 ms
80,672 KB
testcase_13 AC 113 ms
88,940 KB
testcase_14 AC 111 ms
88,512 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