結果

問題 No.672 最長AB列
ユーザー nobigomu
提出日時 2018-04-20 17:33:46
言語 Lua
(LuaJit 2.1.1734355927)
結果
AC  
実行時間 61 ms / 2,000 ms
コード長 316 bytes
コンパイル時間 326 ms
コンパイル使用メモリ 5,376 KB
実行使用メモリ 15,432 KB
最終ジャッジ日時 2024-06-27 20:26:14
合計ジャッジ時間 1,373 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 16
権限があれば一括ダウンロードができます

ソースコード

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