結果

問題 No.457 (^^*)
ユーザー 👑 obakyanobakyan
提出日時 2019-04-29 10:46:02
言語 Lua
(LuaJit 2.1.1696795921)
結果
AC  
実行時間 5 ms / 2,000 ms
コード長 1,276 bytes
コンパイル時間 283 ms
コンパイル使用メモリ 5,372 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-25 15:47:53
合計ジャッジ時間 1,112 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 3 ms
4,376 KB
testcase_13 AC 5 ms
4,380 KB
testcase_14 AC 2 ms
4,376 KB
testcase_15 AC 2 ms
4,376 KB
testcase_16 AC 4 ms
4,380 KB
testcase_17 AC 1 ms
4,380 KB
testcase_18 AC 1 ms
4,380 KB
testcase_19 AC 1 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

local str = io.read()
local n = #str
local toji = {}
for i = 1, n + 1 do toji[i] = 0 end
for i = n, 1, -1 do
  if(str:sub(i, i) == ")") then toji[i] = toji[i + 1] + 1 else toji[i] = toji[i + 1] end
end
local lcnt, rcnt = 0, 0
--left
local lpos = 1
while(lpos ~= nil) do
  local bg = str:find("(", lpos, true)
  if(bg == nil) then lpos = nil
  else
    lpos = bg + 1
    local me1 = str:find("^", bg + 1, true)
    if(me1 ~= nil) then
      local me2 = str:find("^", me1 + 1, true)
      if(me2 ~= nil) then
        local kome = str:find("*", me2 + 1, true)
        if(kome ~= nil) then
          lcnt = lcnt + toji[kome + 1]
        else
          break
        end
      else
        break
      end
    else
      break
    end
  end
end

local rpos = 1
while(rpos ~= nil) do
  local bg = str:find("(", rpos, true)
  if(bg == nil) then rpos = nil
  else
    rpos = bg + 1
    local kome = str:find("*", bg + 1, true)
    if(kome ~= nil) then
      local me1 = str:find("^", kome + 1, true)
      if(me1 ~= nil) then
        local me2 = str:find("^", me1 + 1, true)
        if(me2 ~= nil) then
          rcnt = rcnt + toji[me2 + 1]
        else
          break
        end
      else
        break
      end
    else
      break
    end
  end
end

print(lcnt .. " " .. rcnt)
0