結果

問題 No.451 575
コンテスト
ユーザー t8m8⛄️
提出日時 2016-12-02 02:35:30
言語 Nim
(2.2.8)
コンパイル:
nim --nimcache=~ --hints:off -o:a.out -d:release cpp _filename_
実行:
./a.out
結果
WA  
実行時間 -
コード長 796 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 2,631 ms
コンパイル使用メモリ 67,612 KB
実行使用メモリ 6,144 KB
最終ジャッジ日時 2026-03-19 11:06:16
合計ジャッジ時間 6,476 ms
ジャッジサーバーID
(参考情報)
judge3_0 / judge1_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 18 WA * 8 RE * 3
権限があれば一括ダウンロードができます
コンパイルメッセージ
/home/judge/data/code/Main.nim(1, 18) Warning: imported and not used: 'sequtils' [UnusedImport]

ソースコード

diff #
raw source code

import strutils, sequtils, math

var a = newSeq[int64](10000)

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)
    tmp: seq[int64] = @[]

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

  var
    l: int64 = -1
    u = b[0]

  while u - l > 1:
    let m = (u + l) div 2
    a[0] = m
    if f(1, n, b): l = m
    else: u = m

  if l <= 0:
    echo "-1"
    quit()

  a[0] = l
  if f(1, n, b):
    echo n+1
    for i in 0..n:
      echo a[i]
  else: echo "-1"
0