結果
| 問題 |
No.1894 Delete AB
|
| コンテスト | |
| ユーザー |
startcpp
|
| 提出日時 | 2022-04-08 22:54:04 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 443 ms / 2,000 ms |
| コード長 | 587 bytes |
| コンパイル時間 | 605 ms |
| コンパイル使用メモリ | 69,484 KB |
| 実行使用メモリ | 6,820 KB |
| 最終ジャッジ日時 | 2024-11-28 13:51:00 |
| 合計ジャッジ時間 | 2,060 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 14 |
ソースコード
//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;
}
startcpp