結果

問題 No.1894 Delete AB
ユーザー siganaisiganai
提出日時 2022-04-09 16:10:43
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 226 ms / 2,000 ms
コード長 831 bytes
コンパイル時間 2,670 ms
コンパイル使用メモリ 86,404 KB
実行使用メモリ 95,032 KB
最終ジャッジ日時 2023-08-19 20:07:05
合計ジャッジ時間 5,526 ms
ジャッジサーバーID
(参考情報)
judge10 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 144 ms
78,544 KB
testcase_01 AC 190 ms
80,656 KB
testcase_02 AC 168 ms
79,940 KB
testcase_03 AC 205 ms
80,652 KB
testcase_04 AC 213 ms
81,216 KB
testcase_05 AC 180 ms
80,864 KB
testcase_06 AC 226 ms
81,784 KB
testcase_07 AC 194 ms
81,308 KB
testcase_08 AC 195 ms
80,868 KB
testcase_09 AC 186 ms
81,408 KB
testcase_10 AC 169 ms
80,204 KB
testcase_11 AC 175 ms
80,324 KB
testcase_12 AC 192 ms
80,352 KB
testcase_13 AC 161 ms
86,616 KB
testcase_14 AC 170 ms
95,032 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