結果

問題 No.1894 Delete AB
ユーザー manta1130
提出日時 2022-04-15 17:33:05
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
AC  
実行時間 149 ms / 2,000 ms
コード長 521 bytes
コンパイル時間 146 ms
コンパイル使用メモリ 12,800 KB
実行使用メモリ 13,496 KB
最終ジャッジ日時 2024-12-24 21:35:45
合計ジャッジ時間 2,763 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 14
権限があれば一括ダウンロードができます

ソースコード

diff #

def solve():
    n = int(input())
    s = list(input())

    stack = ['P', 'P']
    for idx in reversed(range(n)):
        if s[idx] == 'B':
            stack.append(s[idx])
        else:
            if stack[-1] != 'B':
                stack.append(s[idx])
            elif stack[-2] == 'B':
                del stack[-1]
            else:
                stack.append(s[idx])
        # print(stack)
    stack = stack[::-1]
    del(stack[-2:])
    print(''.join(stack))


t = int(input())
for i in range(t):
    solve()
0