結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 75 ms
15,264 KB
testcase_01 AC 76 ms
15,152 KB
testcase_02 RE -
testcase_03 AC 76 ms
15,112 KB
testcase_04 RE -
testcase_05 RE -
testcase_06 RE -
testcase_07 RE -
testcase_08 AC 76 ms
15,240 KB
testcase_09 AC 78 ms
15,424 KB
testcase_10 AC 127 ms
16,384 KB
testcase_11 AC 223 ms
18,500 KB
testcase_12 AC 269 ms
19,204 KB
testcase_13 AC 267 ms
19,172 KB
testcase_14 RE -
testcase_15 RE -
testcase_16 RE -
testcase_17 RE -
testcase_18 RE -
testcase_19 RE -
testcase_20 AC 84 ms
15,784 KB
testcase_21 AC 79 ms
15,264 KB
testcase_22 AC 78 ms
15,112 KB
testcase_23 AC 266 ms
19,172 KB
testcase_24 AC 193 ms
17,848 KB
testcase_25 AC 75 ms
15,144 KB
testcase_26 RE -
testcase_27 RE -
testcase_28 RE -
testcase_29 RE -
testcase_30 RE -
testcase_31 RE -
testcase_32 RE -
権限があれば一括ダウンロードができます
コンパイルメッセージ
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
  raise unless l<=r
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