結果

問題 No.672 最長AB列
ユーザー simansiman
提出日時 2020-09-29 04:49:52
言語 Ruby
(3.3.0)
結果
AC  
実行時間 199 ms / 2,000 ms
コード長 319 bytes
コンパイル時間 80 ms
コンパイル使用メモリ 11,412 KB
実行使用メモリ 25,128 KB
最終ジャッジ日時 2023-09-16 05:56:51
合計ジャッジ時間 3,695 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 88 ms
15,024 KB
testcase_01 AC 87 ms
15,256 KB
testcase_02 AC 84 ms
15,080 KB
testcase_03 AC 88 ms
15,076 KB
testcase_04 AC 92 ms
15,024 KB
testcase_05 AC 88 ms
15,132 KB
testcase_06 AC 87 ms
15,088 KB
testcase_07 AC 87 ms
15,024 KB
testcase_08 AC 87 ms
15,204 KB
testcase_09 AC 199 ms
25,128 KB
testcase_10 AC 187 ms
20,480 KB
testcase_11 AC 185 ms
20,612 KB
testcase_12 AC 159 ms
15,616 KB
testcase_13 AC 161 ms
15,636 KB
testcase_14 AC 163 ms
15,672 KB
testcase_15 AC 162 ms
15,620 KB
testcase_16 AC 162 ms
15,512 KB
testcase_17 AC 184 ms
20,528 KB
testcase_18 AC 153 ms
15,620 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

S = gets.chomp

counter = Hash.new
counter[0] = -1

a_cnt = 0
b_cnt = 0
ans = 0

S.each_char.with_index do |s, i|
  if s == 'A'
    a_cnt += 1
  else
    b_cnt += 1
  end

  diff = a_cnt - b_cnt

  if counter[diff]
    len = i - counter[diff]
    ans = len if ans < len
  else
    counter[diff] = i
  end
end

puts ans
0