結果

問題 No.731 等差数列がだいすき
ユーザー mai
提出日時 2018-09-07 21:51:27
言語 Ruby
(3.4.1)
結果
WA  
実行時間 -
コード長 335 bytes
コンパイル時間 205 ms
コンパイル使用メモリ 7,424 KB
実行使用メモリ 12,288 KB
最終ジャッジ日時 2024-11-29 12:50:05
合計ジャッジ時間 3,029 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample WA * 3
other WA * 18
権限があれば一括ダウンロードができます
コンパイルメッセージ
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 "#{a} #{b}"
p N.times.map{|i| (A[i]-(b+a*i))**2}.reduce(:+)
0