結果

問題 No.22 括弧の対応
コンテスト
ユーザー nobigomu
提出日時 2018-03-24 17:43:11
言語 Lua
(LuaJit 2.1.1792588164)
コンパイル:
luajit -b _filename_ a.out
実行:
luajit _filename_
結果
WJ  
(最新)
AC  
(最初)
実行時間 -
コード長 357 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
最終ジャッジ日時 2026-08-19 18:05:33
ジャッジサーバーID
(参考情報)
judge3_0 / judge2_0
このコードへのチャレンジ
(要ログイン)

ソースコード

diff #
raw source code

print((function (f)
	return f(io.stdin:read("*l"):match("%d+%s(%d+)"), io.stdin:read("*l"))
end)(function (i, s)
	local n = 0
	if s:sub(i,i) == "(" then
		for j=i,#s do
			n = s:sub(j,j) == "(" and n+1 or n-1
			if n == 0 then return j end
		end
	else
		for j=i,1,-1 do
			n = s:sub(j,j) ~= "(" and n+1 or n-1
			if n == 0 then return j end
		end
	end
end))
0