結果

問題 No.672 最長AB列
ユーザー simansiman
提出日時 2020-09-29 04:48:57
言語 Ruby
(3.3.0)
結果
WA  
実行時間 -
コード長 303 bytes
コンパイル時間 160 ms
コンパイル使用メモリ 11,372 KB
実行使用メモリ 25,244 KB
最終ジャッジ日時 2023-09-16 05:56:48
合計ジャッジ時間 3,982 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 83 ms
15,156 KB
testcase_01 AC 82 ms
15,108 KB
testcase_02 AC 82 ms
15,084 KB
testcase_03 AC 84 ms
15,140 KB
testcase_04 WA -
testcase_05 AC 82 ms
15,352 KB
testcase_06 AC 82 ms
15,280 KB
testcase_07 AC 82 ms
15,272 KB
testcase_08 AC 84 ms
15,360 KB
testcase_09 AC 197 ms
25,244 KB
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 AC 157 ms
15,672 KB
testcase_14 WA -
testcase_15 AC 156 ms
15,616 KB
testcase_16 AC 155 ms
15,640 KB
testcase_17 AC 179 ms
20,756 KB
testcase_18 WA -
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

S = gets.chomp

counter = Hash.new

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