結果

問題 No.451 575
ユーザー yuruhiyayuruhiya
提出日時 2020-10-21 22:36:41
言語 Crystal
(1.11.2)
結果
AC  
実行時間 99 ms / 2,000 ms
コード長 693 bytes
コンパイル時間 16,633 ms
コンパイル使用メモリ 262,736 KB
実行使用メモリ 20,508 KB
最終ジャッジ日時 2023-09-13 12:25:37
合計ジャッジ時間 21,774 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
4,804 KB
testcase_01 AC 2 ms
4,800 KB
testcase_02 AC 2 ms
4,740 KB
testcase_03 AC 3 ms
4,876 KB
testcase_04 AC 2 ms
4,724 KB
testcase_05 AC 6 ms
5,776 KB
testcase_06 AC 15 ms
8,176 KB
testcase_07 AC 70 ms
17,620 KB
testcase_08 AC 3 ms
4,656 KB
testcase_09 AC 4 ms
5,144 KB
testcase_10 AC 27 ms
8,884 KB
testcase_11 AC 78 ms
18,704 KB
testcase_12 AC 99 ms
20,508 KB
testcase_13 AC 98 ms
20,440 KB
testcase_14 AC 3 ms
4,636 KB
testcase_15 AC 5 ms
5,548 KB
testcase_16 AC 15 ms
7,056 KB
testcase_17 AC 71 ms
17,748 KB
testcase_18 AC 71 ms
17,756 KB
testcase_19 AC 48 ms
13,976 KB
testcase_20 AC 6 ms
5,808 KB
testcase_21 AC 4 ms
5,208 KB
testcase_22 AC 3 ms
4,896 KB
testcase_23 AC 97 ms
20,464 KB
testcase_24 AC 54 ms
15,612 KB
testcase_25 AC 3 ms
4,820 KB
testcase_26 AC 2 ms
4,756 KB
testcase_27 AC 3 ms
4,960 KB
testcase_28 AC 4 ms
5,096 KB
testcase_29 AC 10 ms
6,532 KB
testcase_30 AC 72 ms
17,724 KB
testcase_31 AC 2 ms
4,700 KB
testcase_32 AC 26 ms
10,636 KB
権限があれば一括ダウンロードができます

ソースコード

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