結果

問題 No.451 575
ユーザー yuruhiyayuruhiya
提出日時 2020-10-21 22:29:35
言語 Crystal
(1.14.0)
結果
RE  
実行時間 -
コード長 646 bytes
コンパイル時間 11,204 ms
コンパイル使用メモリ 296,576 KB
実行使用メモリ 9,536 KB
最終ジャッジ日時 2024-06-30 21:29:26
合計ジャッジ時間 14,015 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 27 RE * 2
権限があれば一括ダウンロードができます

ソースコード

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

n = read_line.to_i
b = (1..n).map { read_line.to_i64 }
a = Array.new(n + 1, 0i64)
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|
  {1i64 - a[i], 0i64}.max
}
can = (0..n).select { |i| i % 4 == 1 || i % 4 == 2 }.min_of { |i|
  {a[i] - 1i64, 0i64}.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