結果
問題 |
No.1894 Delete AB
|
ユーザー |
![]() |
提出日時 | 2022-04-10 20:40:30 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 19 ms / 2,000 ms |
コード長 | 789 bytes |
コンパイル時間 | 1,873 ms |
コンパイル使用メモリ | 198,448 KB |
最終ジャッジ日時 | 2025-01-28 17:17:24 |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | AC * 14 |
ソースコード
#define rep(i,n) for(int i=0;i<(int)(n);i++) #define ALL(v) v.begin(),v.end() typedef long long ll; #include<bits/stdc++.h> using namespace std; int main(){ ios::sync_with_stdio(false); std::cin.tie(nullptr); int t; cin>>t; while(t--){ int n; string s; cin>>n>>s; stack<char> sta; rep(i,n){ if(sta.size()>=2 && s[i]=='B'){ while(sta.size()>=2){ auto l=sta.top(); sta.pop(); auto r=sta.top(); if(r=='A' && l=='B') sta.pop(); else{ sta.push(l); break; } } } sta.push(s[i]); } string ans; while(!sta.empty()){ auto r=sta.top(); sta.pop(); ans+=r; } reverse(ALL(ans)); cout<<ans<<endl; } return 0; }