結果
| 問題 | No.731 等差数列がだいすき |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2018-09-07 21:51:45 |
| 言語 | Ruby (3.4.1) |
| 結果 |
AC
|
| 実行時間 | 94 ms / 1,500 ms |
| コード長 | 335 bytes |
| 記録 | |
| コンパイル時間 | 298 ms |
| コンパイル使用メモリ | 7,424 KB |
| 実行使用メモリ | 12,288 KB |
| 最終ジャッジ日時 | 2024-11-29 12:53:00 |
| 合計ジャッジ時間 | 2,988 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 18 |
コンパイルメッセージ
Syntax OK
ソースコード
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(:+)