結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 79 ms
15,172 KB
testcase_01 AC 76 ms
15,148 KB
testcase_02 AC 75 ms
15,096 KB
testcase_03 AC 76 ms
15,128 KB
testcase_04 AC 76 ms
15,124 KB
testcase_05 AC 81 ms
15,316 KB
testcase_06 AC 91 ms
15,316 KB
testcase_07 AC 193 ms
16,740 KB
testcase_08 AC 76 ms
15,220 KB
testcase_09 AC 79 ms
15,428 KB
testcase_10 AC 125 ms
16,636 KB
testcase_11 AC 227 ms
18,580 KB
testcase_12 AC 278 ms
19,068 KB
testcase_13 AC 276 ms
19,132 KB
testcase_14 AC 76 ms
15,072 KB
testcase_15 AC 78 ms
15,304 KB
testcase_16 AC 89 ms
15,916 KB
testcase_17 AC 156 ms
16,628 KB
testcase_18 AC 156 ms
16,900 KB
testcase_19 AC 128 ms
16,384 KB
testcase_20 AC 86 ms
15,776 KB
testcase_21 AC 80 ms
15,400 KB
testcase_22 AC 78 ms
15,276 KB
testcase_23 AC 274 ms
19,300 KB
testcase_24 AC 191 ms
17,980 KB
testcase_25 AC 75 ms
15,272 KB
testcase_26 AC 76 ms
15,312 KB
testcase_27 AC 76 ms
15,036 KB
testcase_28 AC 77 ms
15,252 KB
testcase_29 AC 84 ms
15,972 KB
testcase_30 AC 158 ms
16,648 KB
testcase_31 AC 75 ms
15,044 KB
testcase_32 AC 112 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
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]
(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