結果

問題 No.1894 Delete AB
ユーザー HydruHydru
提出日時 2022-04-08 22:22:19
言語 PyPy3
(7.3.13)
結果
AC  
実行時間 141 ms / 2,000 ms
コード長 499 bytes
コンパイル時間 337 ms
コンパイル使用メモリ 86,960 KB
実行使用メモリ 86,616 KB
最終ジャッジ日時 2023-08-19 00:52:30
合計ジャッジ時間 2,708 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 57 ms
71,608 KB
testcase_01 AC 86 ms
79,892 KB
testcase_02 AC 72 ms
79,736 KB
testcase_03 AC 139 ms
78,516 KB
testcase_04 AC 141 ms
78,116 KB
testcase_05 AC 111 ms
77,772 KB
testcase_06 AC 133 ms
78,216 KB
testcase_07 AC 113 ms
77,616 KB
testcase_08 AC 116 ms
77,604 KB
testcase_09 AC 90 ms
77,396 KB
testcase_10 AC 91 ms
77,700 KB
testcase_11 AC 75 ms
76,444 KB
testcase_12 AC 73 ms
77,288 KB
testcase_13 AC 75 ms
86,616 KB
testcase_14 AC 69 ms
79,600 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

T = int(input())
for _ in range(T):
    N = int(input())
    S = list(input())
    ans = [S[-1]]
    B_count = 0
    if S[-1]=="B":
        B_count+=1
    for i in range(-2,-(N+1),-1):
        if S[i] == "B":
            B_count+=1
            ans.append("B")
        else:
            if B_count>=2 and ans[-1]=="B":
                ans.pop()
                B_count-=1
            else:
                B_count = 0
                ans.append("A")
                
    print("".join(reversed(ans)))
0