結果

問題 No.672 最長AB列
コンテスト
ユーザー nobigomu
提出日時 2018-04-20 17:33:46
言語 Lua
(LuaJit 2.1.1774638290)
コンパイル:
luajit -b _filename_ a.out
実行:
luajit _filename_
結果
AC  
実行時間 42 ms / 2,000 ms
コード長 316 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 199 ms
コンパイル使用メモリ 7,968 KB
実行使用メモリ 15,564 KB
最終ジャッジ日時 2026-03-15 22:50:44
合計ジャッジ時間 1,152 ms
ジャッジサーバーID
(参考情報)
judge3_1 / judge1_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 16
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

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