結果

問題 No.672 最長AB列
コンテスト
ユーザー torus711
提出日時 2019-01-26 16:50:48
言語 Ruby
(4.0.2)
コンパイル:
ruby -w -c _filename_
実行:
ruby _filename_
結果
AC  
実行時間 223 ms / 2,000 ms
コード長 324 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 108 ms
コンパイル使用メモリ 8,960 KB
実行使用メモリ 47,616 KB
最終ジャッジ日時 2026-04-05 11:20:04
合計ジャッジ時間 3,748 ms
ジャッジサーバーID
(参考情報)
judge2_1 / judge1_1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 16
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #
raw source code

S = gets.strip

L = S.size

occurrences = Array.new( L * 2 + 2 ) { Array.new }
occurrences[L] << 0

depth = 0
L.times do |i|
	depth += if S[i] == 'A' then 1 else -1 end
	occurrences[ L + depth ] << i + 1
end

res = 0
occurrences.each do |ary|
	if !ary.empty? then
		res = [ res, ary.last - ary.first ].max
	end
end

puts res
0