結果

問題 No.672 最長AB列
ユーザー Junpei KuriyamaJunpei Kuriyama
提出日時 2019-01-26 15:30:42
言語 Ruby
(3.3.0)
結果
TLE  
実行時間 -
コード長 472 bytes
コンパイル時間 35 ms
コンパイル使用メモリ 11,248 KB
実行使用メモリ 56,276 KB
最終ジャッジ日時 2023-10-14 10:13:57
合計ジャッジ時間 4,612 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 80 ms
19,616 KB
testcase_01 AC 78 ms
15,256 KB
testcase_02 AC 79 ms
15,128 KB
testcase_03 AC 77 ms
15,116 KB
testcase_04 AC 78 ms
15,032 KB
testcase_05 AC 77 ms
15,172 KB
testcase_06 AC 78 ms
15,244 KB
testcase_07 AC 77 ms
15,076 KB
testcase_08 AC 78 ms
15,036 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
balanced_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 >= max_length

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

puts max_length
0