結果

問題 No.672 最長AB列
ユーザー torus711torus711
提出日時 2019-01-26 16:50:48
言語 Ruby
(3.2.2)
結果
AC  
実行時間 341 ms / 2,000 ms
コード長 324 bytes
コンパイル時間 437 ms
コンパイル使用メモリ 11,204 KB
実行使用メモリ 50,392 KB
最終ジャッジ日時 2023-10-14 11:05:50
合計ジャッジ時間 6,045 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 81 ms
15,244 KB
testcase_01 AC 79 ms
15,200 KB
testcase_02 AC 81 ms
15,140 KB
testcase_03 AC 81 ms
15,040 KB
testcase_04 AC 80 ms
15,124 KB
testcase_05 AC 80 ms
15,132 KB
testcase_06 AC 80 ms
15,088 KB
testcase_07 AC 80 ms
15,200 KB
testcase_08 AC 78 ms
15,192 KB
testcase_09 AC 341 ms
48,184 KB
testcase_10 AC 334 ms
48,120 KB
testcase_11 AC 334 ms
48,248 KB
testcase_12 AC 339 ms
50,032 KB
testcase_13 AC 329 ms
50,280 KB
testcase_14 AC 333 ms
50,152 KB
testcase_15 AC 335 ms
50,392 KB
testcase_16 AC 331 ms
50,136 KB
testcase_17 AC 338 ms
48,124 KB
testcase_18 AC 332 ms
49,936 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

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