結果
問題 | No.1894 Delete AB |
ユーザー |
|
提出日時 | 2022-09-25 00:34:08 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 8 ms / 2,000 ms |
コード長 | 669 bytes |
コンパイル時間 | 2,271 ms |
コンパイル使用メモリ | 197,808 KB |
最終ジャッジ日時 | 2025-02-07 14:34:26 |
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | AC * 14 |
ソースコード
#include<bits/stdc++.h>using namespace std;int main(){ios::sync_with_stdio(false);cin.tie(nullptr);int T;cin>>T;while(T--){int N;string S;cin>>N>>S;stack<char>f;for(int i=N-1;i>=0;i--){if(S[i]=='B'){if(i>0&&S[i-1]=='A'&&f.size()&&f.top()=='B'){--i;}else{f.push('B');}}else{if(f.size()&&f.top()=='B'){f.pop();if(f.empty()||f.top()=='A'){f.push('B');f.push('A');}}else{f.push('A');}}}while(f.size()){cout<<f.top();f.pop();}cout<<'\n';}}