結果
| 問題 |
No.884 Eat and Add
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2019-09-16 23:52:51 |
| 言語 | Lua (LuaJit 2.1.1734355927) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 832 bytes |
| コンパイル時間 | 217 ms |
| コンパイル使用メモリ | 7,072 KB |
| 実行使用メモリ | 6,948 KB |
| 最終ジャッジ日時 | 2024-07-07 02:36:30 |
| 合計ジャッジ時間 | 828 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 5 WA * 4 |
ソースコード
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)