結果

問題 No.884 Eat and Add
ユーザー 👑 obakyanobakyan
提出日時 2019-09-16 23:52:51
言語 Lua
(LuaJit 2.1.1696795921)
結果
WA  
実行時間 -
コード長 832 bytes
コンパイル時間 152 ms
コンパイル使用メモリ 5,216 KB
実行使用メモリ 4,480 KB
最終ジャッジ日時 2023-09-21 08:11:41
合計ジャッジ時間 1,069 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

local s = io.read()
local n = #s
local t = {}
local curlen = 1
for i = 2, n do
  if s:sub(i, i) == "0" then
    table.insert(t, curlen)
    curlen = 0
  else
    if curlen == 0 then table.insert(t, 0) end
    curlen = curlen + 1
  end
end
table.insert(t, curlen)
table.insert(t, 0)
local cnt = 0
local curleft = 1
local curpos = 2
while curpos <= #t do
  if curpos == #t or t[curpos + 1] == 0 then
    if 1 < t[curleft] then
      cnt = cnt + 2
    else
      cnt = cnt + 1
    end
    while curpos <= #t and t[curpos] == 0 do
      curpos = curpos + 1
    end
    curleft = curpos
    curpos = curleft + 1
  else
    if 1 < t[curleft] or 1 < t[curpos] then
      cnt = cnt + 1
      t[curleft] = 2
      curpos = curpos + 2
    else
      cnt = cnt + 1
      curleft = curpos
      curpos = curpos + 2
    end
  end
end
print(cnt)
0