結果

問題 No.1894 Delete AB
ユーザー startcppstartcpp
提出日時 2022-04-08 22:54:04
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 341 ms / 2,000 ms
コード長 587 bytes
コンパイル時間 590 ms
コンパイル使用メモリ 68,736 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-19 01:26:24
合計ジャッジ時間 2,265 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

//TLE
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
using namespace std;

int main() {
	int T;
	cin >> T;
	while (T--) {
		int n;
		string s;
		cin >> n >> s;
		
		int i, j;
		string ans;
		for (i = 0; i < n; ) {
			if (s[i] == 'B') { ans += s[i]; i++; } //消せないので追加
			else {
				int cnt = 0;
				for (j = i; j < n; j++) {
					if (s[j] == 'A') cnt++;
					else cnt--;
					if (cnt < 0) break; //消せる
				}
				if (j == n) {
					ans += s[i];
					i++;
				}
				else {
					i = j;
				}
			}
		}
		cout << ans << endl;
	}
	return 0;
}
0