結果

問題 No.672 最長AB列
ユーザー Junpei KuriyamaJunpei Kuriyama
提出日時 2019-01-26 16:04:16
言語 Ruby
(3.3.0)
結果
WA  
実行時間 -
コード長 634 bytes
コンパイル時間 85 ms
コンパイル使用メモリ 11,232 KB
実行使用メモリ 155,660 KB
最終ジャッジ日時 2023-10-14 10:14:56
合計ジャッジ時間 4,602 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 AC 80 ms
15,036 KB
testcase_03 AC 80 ms
15,052 KB
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

if a.to_s.count('A') == 0 || a.to_s.count('B') == 0
  (0..a.length).each do |i|
    descend_str_length = a[0, i].to_s.length
    descend_str_A = a[0, i].to_s.count('A')
    ascend_str_length = a[i, a.length].to_s.length
    ascend_str_A = a[i, a.length].to_s.count('A')
  
    balanced_length = descend_str_length / 2 == descend_str_A ? descend_str_A * 2 : 0
    max_length = balanced_length if balanced_length >= max_length
  
    balanced_length = ascend_str_length / 2 == ascend_str_A ? ascend_str_A * 2 : 0
    max_length = balanced_length if balanced_length >= max_length
  end
end

puts max_length
0