結果

問題 No.451 575
ユーザー yuruhiyayuruhiya
提出日時 2020-10-21 22:29:35
言語 Crystal
(1.11.2)
結果
RE  
実行時間 -
コード長 646 bytes
コンパイル時間 17,720 ms
コンパイル使用メモリ 256,148 KB
実行使用メモリ 10,996 KB
最終ジャッジ日時 2023-09-13 12:26:24
合計ジャッジ時間 21,037 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,352 KB
testcase_01 AC 3 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,428 KB
testcase_04 AC 2 ms
4,384 KB
testcase_05 AC 3 ms
4,808 KB
testcase_06 AC 5 ms
5,060 KB
testcase_07 RE -
testcase_08 AC 2 ms
4,504 KB
testcase_09 AC 3 ms
4,532 KB
testcase_10 AC 9 ms
6,088 KB
testcase_11 AC 22 ms
9,720 KB
testcase_12 AC 27 ms
10,828 KB
testcase_13 AC 26 ms
10,180 KB
testcase_14 AC 2 ms
4,468 KB
testcase_15 AC 3 ms
4,704 KB
testcase_16 AC 5 ms
5,060 KB
testcase_17 AC 17 ms
7,100 KB
testcase_18 AC 17 ms
7,092 KB
testcase_19 AC 12 ms
6,232 KB
testcase_20 AC 4 ms
4,896 KB
testcase_21 AC 3 ms
4,568 KB
testcase_22 AC 3 ms
4,384 KB
testcase_23 AC 27 ms
10,996 KB
testcase_24 AC 16 ms
9,272 KB
testcase_25 AC 3 ms
4,528 KB
testcase_26 AC 3 ms
4,380 KB
testcase_27 AC 3 ms
4,508 KB
testcase_28 AC 3 ms
4,504 KB
testcase_29 AC 5 ms
4,928 KB
testcase_30 AC 17 ms
7,236 KB
testcase_31 AC 2 ms
4,432 KB
testcase_32 RE -
権限があれば一括ダウンロードができます

ソースコード

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