結果

問題 No.1894 Delete AB
ユーザー monnumonnu
提出日時 2022-04-08 21:58:08
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 22 ms / 2,000 ms
コード長 693 bytes
コンパイル時間 4,399 ms
コンパイル使用メモリ 228,364 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-19 00:34:55
合計ジャッジ時間 4,233 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#include <atcoder/all>
using namespace atcoder;
using ll=long long;
using Graph=vector<vector<int>>;
#define INF 1000000000
#define MOD 998244353
#define MAX 1000

void solve(){
  int N;
  string S;
  cin>>N>>S;
  string T="";
  for(int i=S.size()-1;i>=0;i--){
    if(T.size()>0&&T[T.size()-1]=='B'&&S.size()>=2&&S[S.size()-2]=='A'&&S[S.size()-1]=='B'){
      S.pop_back();
      S.pop_back();
      S.push_back(T[T.size()-1]);
      T.pop_back();
    }else{
      T.push_back(S[S.size()-1]);
      S.pop_back();
    }
  }
  reverse(T.begin(),T.end());
  cout<<T<<'\n';
}

int main(){
  int T;
  cin>>T;
  for(int i=0;i<T;i++){
    solve();
  }
}
0