結果

問題 No.1894 Delete AB
ユーザー simansiman
提出日時 2022-04-09 00:32:15
言語 Ruby
(3.3.0)
結果
AC  
実行時間 232 ms / 2,000 ms
コード長 272 bytes
コンパイル時間 93 ms
コンパイル使用メモリ 7,552 KB
実行使用メモリ 29,568 KB
最終ジャッジ日時 2024-05-06 10:10:28
合計ジャッジ時間 3,400 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 76 ms
12,160 KB
testcase_01 AC 195 ms
12,672 KB
testcase_02 AC 200 ms
12,800 KB
testcase_03 AC 152 ms
12,160 KB
testcase_04 AC 157 ms
12,160 KB
testcase_05 AC 159 ms
12,416 KB
testcase_06 AC 166 ms
12,288 KB
testcase_07 AC 167 ms
12,160 KB
testcase_08 AC 182 ms
12,288 KB
testcase_09 AC 138 ms
12,672 KB
testcase_10 AC 160 ms
12,416 KB
testcase_11 AC 164 ms
12,672 KB
testcase_12 AC 169 ms
12,544 KB
testcase_13 AC 212 ms
20,096 KB
testcase_14 AC 232 ms
29,568 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Main.rb:4: warning: assigned but unused variable - n
Syntax OK

ソースコード

diff #

T = gets.to_i

T.times do
  n = gets.to_i
  s = gets.chomp

  stack = []

  s.each_char do |c|
    stack << c

    while stack.size >= 3 && stack[-3] == 'A' && stack[-2] == 'B' && stack[-1] == 'B'
      stack.pop(3)
      stack << 'B'
    end
  end

  puts stack.join
end
0