結果

問題 No.731 等差数列がだいすき
ユーザー maimai
提出日時 2018-09-07 21:51:45
言語 Ruby
(3.3.0)
結果
AC  
実行時間 83 ms / 1,500 ms
コード長 335 bytes
コンパイル時間 659 ms
コンパイル使用メモリ 11,244 KB
実行使用メモリ 15,304 KB
最終ジャッジ日時 2023-08-19 18:14:10
合計ジャッジ時間 3,805 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 80 ms
15,000 KB
testcase_01 AC 82 ms
15,100 KB
testcase_02 AC 81 ms
15,268 KB
testcase_03 AC 81 ms
15,120 KB
testcase_04 AC 80 ms
15,112 KB
testcase_05 AC 80 ms
15,016 KB
testcase_06 AC 80 ms
15,304 KB
testcase_07 AC 81 ms
15,184 KB
testcase_08 AC 82 ms
15,056 KB
testcase_09 AC 81 ms
15,016 KB
testcase_10 AC 81 ms
15,164 KB
testcase_11 AC 80 ms
15,012 KB
testcase_12 AC 80 ms
15,248 KB
testcase_13 AC 80 ms
15,212 KB
testcase_14 AC 79 ms
15,116 KB
testcase_15 AC 81 ms
15,120 KB
testcase_16 AC 80 ms
15,072 KB
testcase_17 AC 81 ms
15,028 KB
testcase_18 AC 82 ms
15,028 KB
testcase_19 AC 83 ms
15,280 KB
testcase_20 AC 83 ms
15,184 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

def ascan; gets.split.map(&:to_f); end


N = gets.to_i
A = ascan

xy = N.times.map{|i|A[i]*i}.reduce(:+)
y = N.times.map{|i|A[i]}.reduce(:+)
x = N.times.map{|i| i}.reduce(:+)
xx = N.times.map{|i| i*i}.reduce(:+)

div = (xx*N-x*x)
a = (xy*N-x*y)/div
b = (xx*y-xy*x)/div


puts "#{b} #{a}"
p N.times.map{|i| (A[i]-(b+a*i))**2}.reduce(:+)
0