結果

問題 No.672 最長AB列
ユーザー Junpei KuriyamaJunpei Kuriyama
提出日時 2019-01-26 17:18:16
言語 Ruby
(3.3.0)
結果
WA  
実行時間 -
コード長 518 bytes
コンパイル時間 344 ms
コンパイル使用メモリ 11,428 KB
実行使用メモリ 34,208 KB
最終ジャッジ日時 2023-10-14 13:03:17
合計ジャッジ時間 5,226 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
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|
  p 'hoge'
  puts a_arr.index(i)
  puts a_arr_reverse.index(i)

  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