結果
問題 | No.1894 Delete AB |
ユーザー | lanegue |
提出日時 | 2022-04-08 23:11:05 |
言語 | D (dmd 2.109.1) |
結果 |
AC
|
実行時間 | 18 ms / 2,000 ms |
コード長 | 469 bytes |
コンパイル時間 | 2,741 ms |
コンパイル使用メモリ | 217,384 KB |
実行使用メモリ | 6,944 KB |
最終ジャッジ日時 | 2024-06-22 14:53:13 |
合計ジャッジ時間 | 3,131 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | AC * 14 |
ソースコード
import std; void main(){ auto T = readln.chomp.to!int; for(auto t = 0; t < T; t++){ auto N = readln.chomp.to!int; auto S = readln.chomp; auto s = ""; auto b = 0; for(auto i = N - 1; i >= 0; i--){ if(S[i] == 'B'){ b++; continue; } if(b == 0){ s ~= "A"; continue; } b--; if(b == 0 && (s.length == 0 || s[$ - 1] == 'A')){ s ~= "BA"; } } if(b > 0){ s ~= "B".cycle.take(b).to!string; } writeln(s.retro); } }