結果

問題 No.672 最長AB列
ユーザー nobigomunobigomu
提出日時 2018-04-20 17:33:46
言語 Lua
(LuaJit 2.1.1696795921)
結果
AC  
実行時間 63 ms / 2,000 ms
コード長 316 bytes
コンパイル時間 336 ms
コンパイル使用メモリ 5,296 KB
実行使用メモリ 11,976 KB
最終ジャッジ日時 2023-09-10 04:45:05
合計ジャッジ時間 1,531 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 17 ms
9,676 KB
testcase_10 AC 19 ms
9,760 KB
testcase_11 AC 61 ms
11,976 KB
testcase_12 AC 8 ms
4,380 KB
testcase_13 AC 11 ms
4,380 KB
testcase_14 AC 7 ms
4,376 KB
testcase_15 AC 7 ms
4,380 KB
testcase_16 AC 10 ms
4,380 KB
testcase_17 AC 63 ms
11,780 KB
testcase_18 AC 8 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

print((function (s)
	local h,t,m,r = {[0]={0}},0,math.floor(#s/2),0

	for i=1,#s do
		t = s:sub(i,i)=="A" and t+1 or t-1
		if t<=m and -m<=t then if h[t] == nil then h[t]={i} else h[t][2]=i end end
	end
	for _,v in pairs(h) do if #v==2 and v[2]-v[1]>r then r = v[2]-v[1] end end

	return r
end)(io.stdin:read("*l")))
0