結果

問題 No.451 575
ユーザー ikdikd
提出日時 2017-03-31 19:10:59
言語 Ruby
(3.3.0)
結果
AC  
実行時間 281 ms / 2,000 ms
コード長 418 bytes
コンパイル時間 50 ms
コンパイル使用メモリ 11,548 KB
実行使用メモリ 19,276 KB
最終ジャッジ日時 2023-09-21 10:44:34
合計ジャッジ時間 6,756 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 89 ms
15,132 KB
testcase_01 AC 78 ms
15,100 KB
testcase_02 AC 79 ms
15,092 KB
testcase_03 AC 79 ms
15,284 KB
testcase_04 AC 79 ms
15,200 KB
testcase_05 AC 84 ms
15,304 KB
testcase_06 AC 97 ms
15,204 KB
testcase_07 AC 196 ms
16,676 KB
testcase_08 AC 77 ms
15,148 KB
testcase_09 AC 81 ms
15,584 KB
testcase_10 AC 133 ms
16,608 KB
testcase_11 AC 234 ms
18,580 KB
testcase_12 AC 281 ms
19,224 KB
testcase_13 AC 281 ms
19,136 KB
testcase_14 AC 85 ms
15,076 KB
testcase_15 AC 85 ms
15,200 KB
testcase_16 AC 95 ms
15,896 KB
testcase_17 AC 156 ms
16,772 KB
testcase_18 AC 156 ms
16,712 KB
testcase_19 AC 132 ms
16,312 KB
testcase_20 AC 89 ms
15,916 KB
testcase_21 AC 86 ms
15,368 KB
testcase_22 AC 81 ms
15,028 KB
testcase_23 AC 276 ms
19,276 KB
testcase_24 AC 197 ms
17,732 KB
testcase_25 AC 80 ms
15,160 KB
testcase_26 AC 81 ms
15,296 KB
testcase_27 AC 83 ms
15,128 KB
testcase_28 AC 91 ms
15,372 KB
testcase_29 AC 89 ms
15,612 KB
testcase_30 AC 155 ms
16,852 KB
testcase_31 AC 82 ms
15,264 KB
testcase_32 AC 115 ms
15,740 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 if 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