結果

問題 No.451 575
ユーザー ikdikd
提出日時 2017-03-31 18:44:26
言語 Ruby
(3.3.0)
結果
AC  
実行時間 287 ms / 2,000 ms
コード長 357 bytes
コンパイル時間 62 ms
コンパイル使用メモリ 11,304 KB
実行使用メモリ 19,232 KB
最終ジャッジ日時 2023-09-21 10:43:11
合計ジャッジ時間 7,536 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 87 ms
15,072 KB
testcase_01 AC 87 ms
15,316 KB
testcase_02 AC 85 ms
15,072 KB
testcase_03 AC 84 ms
15,148 KB
testcase_04 AC 93 ms
15,136 KB
testcase_05 AC 92 ms
15,316 KB
testcase_06 AC 105 ms
15,464 KB
testcase_07 AC 212 ms
16,616 KB
testcase_08 AC 86 ms
15,156 KB
testcase_09 AC 89 ms
15,292 KB
testcase_10 AC 137 ms
16,520 KB
testcase_11 AC 239 ms
18,680 KB
testcase_12 AC 285 ms
19,124 KB
testcase_13 AC 286 ms
19,232 KB
testcase_14 AC 83 ms
15,292 KB
testcase_15 AC 89 ms
15,288 KB
testcase_16 AC 100 ms
15,884 KB
testcase_17 AC 172 ms
16,880 KB
testcase_18 AC 167 ms
16,892 KB
testcase_19 AC 142 ms
16,608 KB
testcase_20 AC 95 ms
15,980 KB
testcase_21 AC 89 ms
15,332 KB
testcase_22 AC 83 ms
15,080 KB
testcase_23 AC 287 ms
19,100 KB
testcase_24 AC 204 ms
17,936 KB
testcase_25 AC 85 ms
15,040 KB
testcase_26 AC 90 ms
15,112 KB
testcase_27 AC 85 ms
15,132 KB
testcase_28 AC 88 ms
15,384 KB
testcase_29 AC 96 ms
15,768 KB
testcase_30 AC 167 ms
16,724 KB
testcase_31 AC 86 ms
15,112 KB
testcase_32 AC 129 ms
15,544 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

n=gets.to_i
b=[]
n.times do
  b<< gets.to_i
end

l, r=1, 10**18
b.each_with_index do |e, i|
  if i.even?
    l, r=[1, e-r].max, e-l
  else
    l, r=[1, l-e].max, r-e
  end
end

if l>r
  puts (-1)
  exit(0)
end

a=[(l+r)/2]
(n-1).downto 0 do |i|
  if (i+1).even?
    a<< b[i]+a.last
  else
    a<< b[i]-a.last
  end
end

puts a.size
a.reverse.map{|e| puts e}
0