結果

問題 No.1894 Delete AB
コンテスト
ユーザー とりゐ
提出日時 2022-04-08 21:31:44
言語 PyPy3
(7.3.17)
コンパイル:
pypy3 -mpy_compile _filename_
実行:
pypy3 _filename_
結果
WA  
実行時間 -
コード長 934 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 312 ms
コンパイル使用メモリ 84,608 KB
実行使用メモリ 87,168 KB
最終ジャッジ日時 2026-05-22 13:02:01
合計ジャッジ時間 2,509 ms
ジャッジサーバーID
(参考情報)
judge3_0 / judge2_1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 2 WA * 12
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

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