結果

問題 No.451 575
ユーザー ikdikd
提出日時 2017-03-31 19:08:54
言語 Ruby
(3.3.0)
結果
RE  
実行時間 -
コード長 415 bytes
コンパイル時間 203 ms
コンパイル使用メモリ 11,496 KB
実行使用メモリ 17,068 KB
最終ジャッジ日時 2023-09-21 10:44:27
合計ジャッジ時間 8,135 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 RE -
testcase_01 RE -
testcase_02 AC 85 ms
15,320 KB
testcase_03 RE -
testcase_04 AC 83 ms
15,160 KB
testcase_05 AC 86 ms
15,204 KB
testcase_06 AC 98 ms
15,496 KB
testcase_07 AC 202 ms
16,892 KB
testcase_08 RE -
testcase_09 RE -
testcase_10 RE -
testcase_11 RE -
testcase_12 RE -
testcase_13 RE -
testcase_14 AC 85 ms
15,272 KB
testcase_15 AC 87 ms
15,324 KB
testcase_16 AC 100 ms
16,060 KB
testcase_17 AC 162 ms
16,668 KB
testcase_18 AC 162 ms
16,896 KB
testcase_19 AC 135 ms
16,316 KB
testcase_20 RE -
testcase_21 RE -
testcase_22 RE -
testcase_23 RE -
testcase_24 RE -
testcase_25 RE -
testcase_26 AC 82 ms
15,128 KB
testcase_27 AC 88 ms
15,324 KB
testcase_28 AC 82 ms
15,144 KB
testcase_29 AC 91 ms
15,800 KB
testcase_30 AC 157 ms
16,728 KB
testcase_31 AC 83 ms
15,328 KB
testcase_32 AC 120 ms
15,704 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

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

l, r=1, 10**18
minus=false
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
  minus|=(l>r)
end

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

raise minus

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

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