結果

問題 No.672 最長AB列
ユーザー nobigomunobigomu
提出日時 2018-04-20 17:31:27
言語 Lua
(LuaJit 2.1.1696795921)
結果
AC  
実行時間 100 ms / 2,000 ms
コード長 401 bytes
コンパイル時間 84 ms
コンパイル使用メモリ 5,328 KB
実行使用メモリ 8,872 KB
最終ジャッジ日時 2023-09-10 04:44:26
合計ジャッジ時間 1,423 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 18 ms
6,652 KB
testcase_10 AC 34 ms
6,548 KB
testcase_11 AC 99 ms
8,872 KB
testcase_12 AC 14 ms
4,376 KB
testcase_13 AC 23 ms
4,376 KB
testcase_14 AC 15 ms
4,376 KB
testcase_15 AC 11 ms
4,376 KB
testcase_16 AC 14 ms
4,380 KB
testcase_17 AC 100 ms
8,868 KB
testcase_18 AC 19 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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