結果

問題 No.1894 Delete AB
ユーザー HydruHydru
提出日時 2022-04-08 22:22:19
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 163 ms / 2,000 ms
コード長 499 bytes
コンパイル時間 372 ms
コンパイル使用メモリ 82,560 KB
実行使用メモリ 78,080 KB
最終ジャッジ日時 2024-05-06 07:55:21
合計ジャッジ時間 2,661 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 41 ms
51,712 KB
testcase_01 AC 66 ms
70,784 KB
testcase_02 AC 65 ms
69,888 KB
testcase_03 AC 129 ms
76,544 KB
testcase_04 AC 163 ms
76,928 KB
testcase_05 AC 117 ms
76,288 KB
testcase_06 AC 147 ms
76,928 KB
testcase_07 AC 125 ms
76,544 KB
testcase_08 AC 126 ms
76,544 KB
testcase_09 AC 93 ms
76,032 KB
testcase_10 AC 100 ms
76,544 KB
testcase_11 AC 72 ms
71,552 KB
testcase_12 AC 68 ms
70,400 KB
testcase_13 AC 68 ms
78,080 KB
testcase_14 AC 60 ms
69,120 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