結果

問題 No.1894 Delete AB
ユーザー Kome_soudouKome_soudou
提出日時 2022-05-21 17:22:22
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 25 ms / 2,000 ms
コード長 579 bytes
コンパイル時間 1,665 ms
コンパイル使用メモリ 173,148 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-20 16:26:41
合計ジャッジ時間 3,741 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,348 KB
testcase_01 AC 10 ms
4,348 KB
testcase_02 AC 10 ms
4,348 KB
testcase_03 AC 22 ms
4,348 KB
testcase_04 AC 23 ms
4,348 KB
testcase_05 AC 22 ms
4,348 KB
testcase_06 AC 23 ms
4,348 KB
testcase_07 AC 23 ms
4,348 KB
testcase_08 AC 25 ms
4,348 KB
testcase_09 AC 7 ms
4,348 KB
testcase_10 AC 9 ms
4,348 KB
testcase_11 AC 8 ms
4,348 KB
testcase_12 AC 8 ms
4,348 KB
testcase_13 AC 8 ms
4,348 KB
testcase_14 AC 8 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

int main()
{
	int T;
	cin >> T;
	int N;
	string S;
	deque<char> dq;
	int ds;
	for(int t = 0; t < T; t++)
	{
		cin >> N >> S;
		for(int i = 0; i < N; i++)
		{
			dq.push_back(S[i]);
			while((int)dq.size() >= 3)
			{
				ds = (int)dq.size();
				if(dq[ds - 3] == 'A' && dq[ds - 2] == 'B' && dq[ds - 1] == 'B')
				{
					dq.pop_back();
					dq.pop_back();
					dq.pop_back();
					dq.push_back('B');
				}
				else break;
			}
		}
		while(!dq.empty())
		{
			cout << dq.front();
			dq.pop_front();
		}
		cout << endl;
	}
	return 0;
}
0