結果

問題 No.1894 Delete AB
ユーザー Kanten4205Kanten4205
提出日時 2022-02-26 08:25:09
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 27 ms / 2,000 ms
コード長 672 bytes
コンパイル時間 2,203 ms
コンパイル使用メモリ 170,212 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-20 06:19:10
合計ジャッジ時間 3,738 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
int main() {
    int T; cin >> T;
    while (T--) {
        int N; cin >> N;
        string S; cin >> S;
        stack<char>C;
        C.push(S.back());
        S.pop_back();
        while (!S.empty()) {
            if (C.top() == 'B' && S.back() == 'A') {
                if ((int)C.size() == 1) {C.push('A');S.pop_back();continue;}
                C.pop();
                if (C.top() == 'A') {C.push('B'); C.push('A');}
            }
            else C.push(S.back());
            S.pop_back();
        }
        while (!C.empty()) {
            cout << C.top();
            C.pop();
        }
        cout << endl;
    }
}
0