結果

問題 No.1894 Delete AB
ユーザー siganaisiganai
提出日時 2022-04-09 16:10:43
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 160 ms / 2,000 ms
コード長 831 bytes
コンパイル時間 297 ms
コンパイル使用メモリ 81,920 KB
実行使用メモリ 97,024 KB
最終ジャッジ日時 2024-05-07 03:01:20
合計ジャッジ時間 3,820 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 65 ms
64,128 KB
testcase_01 AC 111 ms
77,952 KB
testcase_02 AC 106 ms
77,824 KB
testcase_03 AC 134 ms
78,208 KB
testcase_04 AC 145 ms
78,080 KB
testcase_05 AC 114 ms
77,440 KB
testcase_06 AC 160 ms
78,464 KB
testcase_07 AC 132 ms
78,080 KB
testcase_08 AC 131 ms
77,696 KB
testcase_09 AC 124 ms
77,824 KB
testcase_10 AC 109 ms
77,440 KB
testcase_11 AC 110 ms
77,568 KB
testcase_12 AC 127 ms
77,440 KB
testcase_13 AC 87 ms
78,720 KB
testcase_14 AC 111 ms
97,024 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#!/usr/bin/env PyPy3

from collections import Counter, defaultdict, deque
import itertools
import re
import math
from functools import reduce
import operator
import bisect
import heapq
import functools
mod=10**9+7

import sys
input=sys.stdin.readline

t = int(input())
for _ in range(t):
    n=int(input())
    s=input().rstrip()
    ans = []
    for i in range(n):
        if ans:
            if ans[-1] == 'A' and s[i] == 'B':
                if i + 1 < n and s[i+1] == 'B':
                    ans.pop()
                    while len(ans) >= 2 and ans[-2] == 'A' and ans[-1] == 'B':
                        ans.pop()
                        ans.pop()
                else:
                    ans.append(s[i])
            else:
                ans.append(s[i])
        else:
            ans.append(s[i])
    print(''.join(ans))
0