結果

問題 No.451 575
ユーザー yuruhiya
提出日時 2020-10-21 22:36:41
言語 Crystal
(1.14.0)
結果
AC  
実行時間 96 ms / 2,000 ms
コード長 693 bytes
コンパイル時間 11,430 ms
コンパイル使用メモリ 304,248 KB
実行使用メモリ 17,152 KB
最終ジャッジ日時 2024-06-30 21:28:55
合計ジャッジ時間 15,550 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 29
権限があれば一括ダウンロードができます

ソースコード

diff #

lib C
  fun strtoll(s : UInt8*, p : UInt8**, b : Int32) : Int64
end

class String
  def to_i64
    C.strtoll(self, nil, 10)
  end
end

require "big"

n = read_line.to_i
b = (1..n).map { read_line.to_big_i }
a = Array.new(n + 1, 0.to_big_i)
n.times { |i| a[i + 1] = i.even? ? b[i] - a[i] : a[i] - b[i] }

need = (0..n).select { |i| i % 4 == 0 || i % 4 == 3 }.max_of { |i|
  {1.to_big_i - a[i], 0.to_big_i}.max
}
can = (0..n).select { |i| i % 4 == 1 || i % 4 == 2 }.min_of { |i|
  {a[i] - 1.to_big_i, 0.to_big_i}.max
}

if need <= can
  (0..n).each do |i|
    if i % 4 == 0 || i % 4 == 3
      a[i] += need
    else
      a[i] -= need
    end
  end
  puts n + 1, a.join("\n")
else
  puts -1
end
0