結果

問題 No.1894 Delete AB
ユーザー とりゐ
提出日時 2022-04-08 21:31:44
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 934 bytes
コンパイル時間 480 ms
コンパイル使用メモリ 82,168 KB
実行使用メモリ 92,032 KB
最終ジャッジ日時 2024-11-28 12:07:41
合計ジャッジ時間 2,860 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 2 WA * 12
権限があれば一括ダウンロードができます

ソースコード

diff #

import math
from collections import deque,Counter
from sys import stdin

#sys.setrecursionlimit(10**7)

int1=lambda x: int(x)-1
stinput=lambda :stdin.readline()[:-1]
ii=lambda :int(stinput())
mi=lambda :map(int, stdin.readline().split())
li=lambda :list(mi())
mi1=lambda :map(int1, stdin.readline().split())
li1=lambda :list(mi1())
mis=lambda :map(str, stdin.readline().split())
lis=lambda :list(mis())

from collections import defaultdict
#d=defaultdict(int)
#d=defaultdict(lambda:1)

mod=10**9+7
Mod=998244353
INF=10**18
ans=0

def solve():
  n=ii()
  s=input()
  s=list(s)
  t=[]
  if s[-1]=='A':
    t.append(s.pop())
  while len(s)>=2 and s[-2]+s[-1]=='AB':
    t.append(s.pop())
    t.append(s.pop())
  #print(s,t)
  d=[]
  for i in s:
    d.append(i)
    if len(d)>=2 and d[-2]+d[-1]=='AB':
      d.pop()
      d.pop()
  ans=d+t[::-1]
  if len(ans)==0:
    ans.append('AB')
  print(''.join(ans))
for _ in range(ii()):
  solve()
0