結果

問題 No.1894 Delete AB
ユーザー lloyzlloyz
提出日時 2022-04-08 23:12:19
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 594 bytes
コンパイル時間 379 ms
コンパイル使用メモリ 82,564 KB
実行使用メモリ 263,936 KB
最終ジャッジ日時 2024-05-06 08:57:12
合計ジャッジ時間 3,971 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 37 ms
51,968 KB
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 AC 1,060 ms
130,304 KB
testcase_14 TLE -
権限があれば一括ダウンロードができます

ソースコード

diff #

t = int(input())
for _ in range(t):
    n = int(input())
    S = input()
    ANS = ''
    res = 0
    for i in range(n):
        s = S[i]
        if s == 'A':
            ANS += s
        elif s == 'B' and len(ANS) > 0 and ANS[-1] == 'A':
            if i < n - 1 and S[i + 1] > ANS[-1]:
                ANS = ANS[:-1]
            else:
                ANS += s
        else:
            ANS += s
    res = 0
    for i in range(0, len(ANS), 2):
        if ANS[i:i + 2] == 'AB':
            res += 2
        else:
            break
    if len(ANS) != res:
        ANS = ANS[res:]
    print(ANS)
0