結果

問題 No.1894 Delete AB
ユーザー kyawa
提出日時 2022-05-06 20:10:55
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 29 ms / 2,000 ms
コード長 700 bytes
コンパイル時間 1,940 ms
コンパイル使用メモリ 195,268 KB
最終ジャッジ日時 2025-01-29 02:58:23
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 14
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;

int main(){
    int64_t T; cin >> T;
    while(T--){
        int64_t N; cin >> N;
        string S; cin >> S;
        string res = "";
        for(auto c : S){
            res.push_back(c);
            while(true){
                int64_t sz = res.size();
                if(res.size() < 3) break;
                if(res[sz-3] == 'A' and res[sz-2] == 'B' and res[sz-1] == 'B'){
                    res.pop_back();
                    res.pop_back();
                    res.pop_back();
                    res.push_back('B');
                }else{
                    break;
                }
            }
        }
        cout << res << '\n';
    }
}
0