結果

問題 No.672 最長AB列
コンテスト
ユーザー Junpei Kuriyama
提出日時 2019-01-26 15:28:29
言語 Ruby
(4.0.2)
コンパイル:
ruby -w -c _filename_
実行:
ruby _filename_
結果
RE  
実行時間 -
コード長 470 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 68 ms
コンパイル使用メモリ 8,960 KB
実行使用メモリ 49,980 KB
最終ジャッジ日時 2026-04-05 10:21:04
合計ジャッジ時間 4,610 ms
ジャッジサーバーID
(参考情報)
judge2_1 / judge1_1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1 RE * 2
other AC * 2 RE * 5 TLE * 1 -- * 8
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #
raw source code

a = gets.chomp
max_length = 0

(0..a.length).each do |i|
  descend_str, ascend_str = a[0, i-1].to_s, a[i-1, a.length].to_s

  balanced_length = descend_str.length if descend_str.count('A') == descend_str.count('B')
  max_length = balanced_length if ((balanced_length || 0) >= max_length)

  balanced_length = ascend_str.length if ascend_str.count('A') == ascend_str.count('B')
  max_length = balanced_length if ((balanced_length || 0) >= max_length)
end

puts max_length
0