結果

問題 No.672 最長AB列
コンテスト
ユーザー Takuya Noguchi
提出日時 2019-02-08 00:46:35
言語 Ruby
(4.0.2)
コンパイル:
ruby -w -c _filename_
実行:
ruby _filename_
結果
WA  
実行時間 -
コード長 310 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 50 ms
コンパイル使用メモリ 8,832 KB
実行使用メモリ 39,036 KB
最終ジャッジ日時 2026-03-13 00:52:18
合計ジャッジ時間 3,378 ms
ジャッジサーバーID
(参考情報)
judge3_1 / judge2_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 10 WA * 6
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #
raw source code

answer = cumulative_sum = 0
distribution = Hash.new(-1)

gets.chomp.chars.each_with_index do |char, i|
  cumulative_sum += char == 'A' ? 1 : -1

  if distribution.key?(cumulative_sum)
    answer = [answer, i - distribution[cumulative_sum]].max
  else
    distribution[cumulative_sum] = i
  end
end

puts answer
0