結果

問題 No.1894 Delete AB
ユーザー ntudantuda
提出日時 2022-11-17 20:45:54
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 146 ms / 2,000 ms
コード長 430 bytes
コンパイル時間 87 ms
コンパイル使用メモリ 11,920 KB
実行使用メモリ 10,424 KB
最終ジャッジ日時 2023-10-19 11:22:31
合計ジャッジ時間 2,363 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 33 ms
10,052 KB
testcase_01 AC 73 ms
10,424 KB
testcase_02 AC 67 ms
10,424 KB
testcase_03 AC 134 ms
10,068 KB
testcase_04 AC 135 ms
10,068 KB
testcase_05 AC 132 ms
10,068 KB
testcase_06 AC 135 ms
10,068 KB
testcase_07 AC 135 ms
10,068 KB
testcase_08 AC 146 ms
10,068 KB
testcase_09 AC 58 ms
10,068 KB
testcase_10 AC 64 ms
10,068 KB
testcase_11 AC 57 ms
10,088 KB
testcase_12 AC 57 ms
10,156 KB
testcase_13 AC 67 ms
10,424 KB
testcase_14 AC 65 ms
10,424 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

T = int(input())
for _ in range(T):
    N = int(input())
    S = input()
    ans = []
    NA, NB = 0, 0
    for s in reversed(S):
        if s == "A":
            if NB == 0:
                ans.append("A")
            elif NB == 1:
                ans.append("AB")
                NB -= 1
            else:
                NB -= 1
        else:
            NB += 1
    ans += ["B"] * NB
    ans.reverse()
    print("".join(ans))
0