結果

問題 No.672 最長AB列
ユーザー Junpei KuriyamaJunpei Kuriyama
提出日時 2019-01-26 15:28:29
言語 Ruby
(3.3.0)
結果
RE  
実行時間 -
コード長 470 bytes
コンパイル時間 63 ms
コンパイル使用メモリ 11,512 KB
実行使用メモリ 56,060 KB
最終ジャッジ日時 2023-10-14 10:13:51
合計ジャッジ時間 5,101 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 RE -
testcase_01 RE -
testcase_02 AC 79 ms
15,244 KB
testcase_03 AC 80 ms
15,248 KB
testcase_04 AC 80 ms
15,072 KB
testcase_05 RE -
testcase_06 RE -
testcase_07 RE -
testcase_08 RE -
testcase_09 RE -
testcase_10 TLE -
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

(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