結果

問題 No.451 575
ユーザー t8m8⛄️t8m8⛄️
提出日時 2016-12-02 06:12:41
言語 Nim
(2.0.2)
結果
WA  
実行時間 -
コード長 1,670 bytes
コンパイル時間 3,351 ms
コンパイル使用メモリ 68,012 KB
実行使用メモリ 4,780 KB
最終ジャッジ日時 2023-09-12 07:55:36
合計ジャッジ時間 8,682 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 3 ms
4,376 KB
testcase_04 WA -
testcase_05 AC 4 ms
4,380 KB
testcase_06 AC 8 ms
4,380 KB
testcase_07 AC 32 ms
4,636 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 AC 169 ms
4,632 KB
testcase_14 AC 2 ms
4,380 KB
testcase_15 AC 4 ms
4,376 KB
testcase_16 AC 8 ms
4,376 KB
testcase_17 AC 33 ms
4,728 KB
testcase_18 WA -
testcase_19 AC 22 ms
4,376 KB
testcase_20 WA -
testcase_21 WA -
testcase_22 AC 3 ms
4,376 KB
testcase_23 WA -
testcase_24 AC 1,533 ms
4,380 KB
testcase_25 AC 2 ms
4,380 KB
testcase_26 WA -
testcase_27 AC 5 ms
4,376 KB
testcase_28 AC 3 ms
4,384 KB
testcase_29 AC 5 ms
4,376 KB
testcase_30 AC 33 ms
4,716 KB
testcase_31 AC 2 ms
4,376 KB
testcase_32 AC 11 ms
4,376 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
/home/judge/data/code/Main.nim(1, 18) Warning: imported and not used: 'sequtils' [UnusedImport]

ソースコード

diff #

import strutils, sequtils, math

var a = newSeq[int64](100010)

proc f(i, n: int, b: seq[int64]): int64 =
  if i > n: return 0
  if i mod 2 == 0:
    a[i] = a[i-1] - b[i-1]
    if a[i] <= 0 or 10^18 < a[i]: return abs(a[i])
    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 abs(a[i])
    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 p = 1
  # while p < b[0]:
  #   a[0] = p
  #   echo f(1, n, b)
  #   p += 1

  var
    l: int64 = -1
    r: int64 = b[0]
    cnt: int = 0
    pos: int64 = -1

  while r - l > 10 and cnt < 1000:
    var
      x = (l + l + r) div 3
      y = (l + r + r) div 3
    a[0] = x
    let xf = f(1, n, b)
    a[0] = y
    let yf = f(1, n, b)
    if xf == 0:
      pos = x
      break
    if yf == 0:
      pos = y
      break
    if xf > yf:
      l = xf
    else:
      r = yf
    cnt += 1

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

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

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


  echo "-1"
0