結果

問題 No.1894 Delete AB
ユーザー SidewaysOwlSidewaysOwl
提出日時 2022-04-08 21:36:42
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 159 ms / 2,000 ms
コード長 589 bytes
コンパイル時間 206 ms
コンパイル使用メモリ 82,140 KB
実行使用メモリ 85,888 KB
最終ジャッジ日時 2024-05-06 07:09:51
合計ジャッジ時間 2,294 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 40 ms
53,632 KB
testcase_01 AC 77 ms
85,640 KB
testcase_02 AC 79 ms
85,248 KB
testcase_03 AC 132 ms
77,696 KB
testcase_04 AC 156 ms
78,052 KB
testcase_05 AC 110 ms
76,940 KB
testcase_06 AC 159 ms
77,824 KB
testcase_07 AC 121 ms
76,984 KB
testcase_08 AC 123 ms
76,792 KB
testcase_09 AC 100 ms
77,708 KB
testcase_10 AC 97 ms
77,184 KB
testcase_11 AC 78 ms
76,352 KB
testcase_12 AC 77 ms
78,552 KB
testcase_13 AC 71 ms
85,888 KB
testcase_14 AC 56 ms
74,496 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import deque
for _ in range(int(input())):
    n = int(input())
    s = list(input())
    res = deque()
    for i in range(n-1,-1,-1):
        if s[i] == "A":
            if len(res) >= 2:
                a,b = res.pop(),res.pop()
                if a == b == "B":
                    res.append("B")
                else:
                    res.append(b)
                    res.append(a)
                    res.append(s[i])
            else:
                res.append(s[i])
        else:
            res.append(s[i])

    res = list(res)[::-1]
    print("".join(res))
0