結果
問題 | No.1894 Delete AB |
ユーザー |
|
提出日時 | 2022-04-08 22:49:47 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 7 ms / 2,000 ms |
コード長 | 1,190 bytes |
コンパイル時間 | 1,802 ms |
コンパイル使用メモリ | 171,048 KB |
実行使用メモリ | 6,820 KB |
最終ジャッジ日時 | 2024-11-28 13:42:06 |
合計ジャッジ時間 | 2,521 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | AC * 14 |
ソースコード
#include <bits/stdc++.h>using namespace std;#ifdef _RUTHEN#include "debug.hpp"#else#define show(...) true#endifusing ll = long long;#define rep(i, n) for (int i = 0; i < (n); i++)template <class T> using V = vector<T>;int main() {ios::sync_with_stdio(false);cin.tie(0);int T;cin >> T;while (T--) {int N;cin >> N;string S;cin >> S;V<char> stk;for (int i = N - 1; i >= 0; i--) {stk.push_back(S[i]);int len = stk.size();if (len >= 2 && stk[len - 1] == 'A' && stk[len - 2] == 'B') {if (len == 2) {continue;} else if (stk[len - 3] == 'B') {stk.pop_back();stk.pop_back();} else if (len == 3) {continue;} else if (stk[len - 4] == 'A') {continue;} else {continue;}}}string ans;for (auto &c : stk) ans += c;reverse(ans.begin(), ans.end());cout << ans << '\n';}return 0;}