結果

問題 No.451 575
ユーザー 👑 obakyanobakyan
提出日時 2020-04-20 23:42:42
言語 Lua
(LuaJit 2.1.1696795921)
結果
AC  
実行時間 224 ms / 2,000 ms
コード長 1,368 bytes
コンパイル時間 70 ms
コンパイル使用メモリ 5,248 KB
実行使用メモリ 13,768 KB
最終ジャッジ日時 2024-04-16 01:05:01
合計ジャッジ時間 4,223 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 1 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 5 ms
5,376 KB
testcase_06 AC 12 ms
5,376 KB
testcase_07 AC 57 ms
10,276 KB
testcase_08 AC 1 ms
5,376 KB
testcase_09 AC 4 ms
5,376 KB
testcase_10 AC 38 ms
5,404 KB
testcase_11 AC 151 ms
11,424 KB
testcase_12 AC 222 ms
13,344 KB
testcase_13 AC 198 ms
13,344 KB
testcase_14 AC 2 ms
5,376 KB
testcase_15 AC 4 ms
5,376 KB
testcase_16 AC 10 ms
5,376 KB
testcase_17 AC 63 ms
10,132 KB
testcase_18 AC 60 ms
10,132 KB
testcase_19 AC 37 ms
6,912 KB
testcase_20 AC 7 ms
5,376 KB
testcase_21 AC 4 ms
5,376 KB
testcase_22 AC 1 ms
5,376 KB
testcase_23 AC 224 ms
13,768 KB
testcase_24 AC 105 ms
9,116 KB
testcase_25 AC 2 ms
5,376 KB
testcase_26 AC 2 ms
5,376 KB
testcase_27 AC 2 ms
5,376 KB
testcase_28 AC 2 ms
5,376 KB
testcase_29 AC 6 ms
5,376 KB
testcase_30 AC 63 ms
10,260 KB
testcase_31 AC 1 ms
5,376 KB
testcase_32 AC 19 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

local function lltonumber(str)
  local ret = 0LL
  for i = 1, #str do
    ret = ret * 10LL + str:sub(i, i):byte() - 48
  end
  return ret
end
local function llprint(llnumber)
  local str = tostring(llnumber):gsub("LL", "")
  print(str)
end

local n = io.read("*n", "*l")
local flag = true
local minlim = 1LL
local maxlim = 1000000000000000000LL
local offset = 0LL
local valid = true
local b = {}
for i = 1, n do
  local bs = io.read()
  b[i] = lltonumber(bs)
  if i % 2 == 1 then
    --a[i+1] = b[i] - a[i]
    flag = not flag
    offset = b[i] - offset
  else
    --a[i+1] = a[i] - b[i]
    offset = offset - b[i]
  end
  if flag then
    local ma = 1000000000000000000LL - offset
    if ma < maxlim then
      maxlim = ma
    end
    -- 1 <= offset + x
    if minlim < 1LL - offset then
      minlim = 1LL - offset
    end
  else
    local ma = offset - 1LL
    if ma < maxlim then
      maxlim = ma
    end
    local mi = offset - 1000000000000000000LL
    if minlim < mi then
      minlim = mi
    end
  end
  -- print(i, tostring(minlim), tostring(maxlim), tostring(offset), flag)
  if maxlim < minlim then
    valid = false
  end
end
if valid then
  print(n + 1)
  local v = minlim
  llprint(v)
  for i = 1, n do
    if i % 2 == 1 then
      --a[i+1] = b[i] - a[i]
      v = b[i] - v
    else
      v = v - b[i]
    end
    llprint(v)
  end
else
  print(-1)
end
0