結果

問題 No.672 最長AB列
ユーザー Junpei KuriyamaJunpei Kuriyama
提出日時 2019-01-26 17:21:23
言語 Ruby
(3.3.0)
結果
TLE  
実行時間 -
コード長 484 bytes
コンパイル時間 393 ms
コンパイル使用メモリ 11,260 KB
実行使用メモリ 23,560 KB
最終ジャッジ日時 2023-10-14 13:27:23
合計ジャッジ時間 5,928 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 81 ms
22,276 KB
testcase_01 AC 82 ms
15,176 KB
testcase_02 AC 81 ms
15,256 KB
testcase_03 AC 80 ms
15,176 KB
testcase_04 AC 80 ms
15,164 KB
testcase_05 AC 81 ms
15,236 KB
testcase_06 AC 81 ms
15,308 KB
testcase_07 AC 80 ms
15,164 KB
testcase_08 AC 83 ms
15,144 KB
testcase_09 TLE -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

a = gets.chomp
max_length = 0
a_arr = []
current = 0

a_arr << current

a.chars do |c|
  if c == "A"
    current = current + 1
    a_arr << current
  end

  if c == "B"
    current = current - 1
    a_arr << current
  end
end

a_arr_reverse = a_arr.reverse

(a_arr.min..a_arr.max).each do |i|
  next if a_arr.count(i) <= 0
  tmp_max_length = a_arr.length - a_arr.index(i) - a_arr_reverse.index(i) - 1
  max_length = tmp_max_length if tmp_max_length >= max_length
end

print max_length
0