結果

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

ソースコード

diff #
raw source code

local ffi = require 'ffi'

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

	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]=ct(i,-1) else h[t].r=i end end
	end
	for _,v in pairs(h) do if v.r~=-1 and v.r-v.l>r then r=v.r-v.l end end

	return r
end)(io.stdin:read("*l"), ffi.typeof("struct { int l; int r; }")))
0