結果
| 問題 |
No.1894 Delete AB
|
| コンテスト | |
| ユーザー |
SidewaysOwl
|
| 提出日時 | 2022-04-08 21:36:42 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
AC
|
| 実行時間 | 167 ms / 2,000 ms |
| コード長 | 589 bytes |
| コンパイル時間 | 178 ms |
| コンパイル使用メモリ | 82,184 KB |
| 実行使用メモリ | 85,832 KB |
| 最終ジャッジ日時 | 2024-11-28 12:14:10 |
| 合計ジャッジ時間 | 2,400 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 14 |
ソースコード
from collections import deque
for _ in range(int(input())):
n = int(input())
s = list(input())
res = deque()
for i in range(n-1,-1,-1):
if s[i] == "A":
if len(res) >= 2:
a,b = res.pop(),res.pop()
if a == b == "B":
res.append("B")
else:
res.append(b)
res.append(a)
res.append(s[i])
else:
res.append(s[i])
else:
res.append(s[i])
res = list(res)[::-1]
print("".join(res))
SidewaysOwl