結果

問題 No.1894 Delete AB
ユーザー karinohitokarinohito
提出日時 2024-02-09 05:44:02
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 27 ms / 2,000 ms
コード長 550 bytes
コンパイル時間 7,852 ms
コンパイル使用メモリ 206,124 KB
実行使用メモリ 6,676 KB
最終ジャッジ日時 2024-02-09 05:44:19
合計ジャッジ時間 3,270 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
void solve(){
    string S;
    int N;
    cin>>N>>S;
    stack<char> C;
    for(int i=N-1;i>=0;i--){
        if(C.size()<2||S[i]=='B')C.push(S[i]);
        else if(C.top()=='B'){
            C.pop();
            if(C.top()!='B'){
                C.push('B');
                C.push('A');
            }
        }
        else C.push(S[i]);
    }
    while(!C.empty()){
        cout<<C.top();
        C.pop();
    }
    cout<<endl;
    return;
}
int main() {
    int T;
    cin>>T;
    while(T--)solve();
}
0