結果

問題 No.451 575
ユーザー t8m8⛄️t8m8⛄️
提出日時 2016-12-02 05:23:25
言語 Nim
(2.0.2)
結果
TLE  
実行時間 -
コード長 1,062 bytes
コンパイル時間 3,041 ms
コンパイル使用メモリ 69,408 KB
実行使用メモリ 10,056 KB
最終ジャッジ日時 2023-09-12 07:55:12
合計ジャッジ時間 7,328 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 3 ms
4,380 KB
testcase_04 TLE -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
権限があれば一括ダウンロードができます
コンパイルメッセージ
/home/judge/data/code/Main.nim(42, 9) Warning: use `delete(s, first..last)`; delete is deprecated [Deprecated]

ソースコード

diff #

import strutils, sequtils, math

var a = newSeq[int64](100010)

proc f(i, n: int, b: seq[int64]): bool =
  if i > n: return true
  if i mod 2 == 0:
    a[i] = a[i-1] - b[i-1]
    if a[i] <= 0 or 10^18 < a[i]: return false
    return f(i+1, n, b)
  else:
    a[i] = b[i-1] - a[i-1]
    if a[i] <= 0 or 10^18 < a[i]: return false
    return f(i+1, n, b)

when isMainModule:
  var
    n = stdin.readLine.parseInt
    b = newSeq[int64](n)

  for i in 0..n-1:
    b[i] = stdin.readLine.parseBiggestInt

  if n == 1:
    if b[0] <= 1: echo "-1"
    else:
      echo 2
      echo 1
      echo b[0] - 1
    quit()


  var
    m: int64 = -1
    que: seq[(int64,int64)] = @[]
    cnt = 0

  que.add((-1.int64, b[0]))

  while que.len > 0 and cnt < 100000:
    var (l, u) = que[0]
    que.delete(0,0)
    m = (l + u) div 2
    a[0] = m
    if f(1, n, b): break
    que.add((l, m))
    que.add((m, u))
    cnt += 1

  for i in max(1, m-100)..min(b[0]-1, m+100):
    a[0] = i
    if f(1, n, b):
      echo n+1
      for i in 0..n:
        echo a[i]
      quit()

  echo "-1"
0