結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 81 ms
15,132 KB
testcase_01 AC 82 ms
15,312 KB
testcase_02 AC 79 ms
15,160 KB
testcase_03 AC 79 ms
15,136 KB
testcase_04 AC 79 ms
15,240 KB
testcase_05 AC 84 ms
15,220 KB
testcase_06 AC 90 ms
15,420 KB
testcase_07 AC 138 ms
16,744 KB
testcase_08 AC 80 ms
15,304 KB
testcase_09 AC 83 ms
15,372 KB
testcase_10 AC 131 ms
16,460 KB
testcase_11 AC 236 ms
18,500 KB
testcase_12 AC 276 ms
19,352 KB
testcase_13 AC 279 ms
19,136 KB
testcase_14 AC 82 ms
15,136 KB
testcase_15 AC 83 ms
15,276 KB
testcase_16 AC 94 ms
16,096 KB
testcase_17 AC 165 ms
16,688 KB
testcase_18 AC 139 ms
16,876 KB
testcase_19 AC 131 ms
16,732 KB
testcase_20 AC 90 ms
15,860 KB
testcase_21 AC 86 ms
15,268 KB
testcase_22 AC 83 ms
15,108 KB
testcase_23 AC 278 ms
19,032 KB
testcase_24 AC 196 ms
18,016 KB
testcase_25 AC 83 ms
15,028 KB
testcase_26 AC 87 ms
15,348 KB
testcase_27 AC 82 ms
15,148 KB
testcase_28 AC 85 ms
15,460 KB
testcase_29 AC 92 ms
15,912 KB
testcase_30 AC 165 ms
16,872 KB
testcase_31 AC 82 ms
15,108 KB
testcase_32 AC 105 ms
15,700 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?
    if e<=l
      puts (-1)
      exit(0)
    end
    l, r=[1, e-r].max, e-l
  else
    if r<=e
      puts (-1)
      exit(0)
    end
    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