結果

問題 No.731 等差数列がだいすき
ユーザー qib
提出日時 2023-03-31 00:24:23
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 39 ms / 1,500 ms
コード長 501 bytes
コンパイル時間 246 ms
コンパイル使用メモリ 82,120 KB
実行使用メモリ 54,636 KB
最終ジャッジ日時 2024-09-22 08:31:19
合計ジャッジ時間 1,994 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 18
権限があれば一括ダウンロードができます

ソースコード

diff #

n = int(input())
a = list(map(float, input().split()))

points = []
mu_x = 0.0
mu_y = 0.0
cov_xy = 0.0
for i in range(n):
  points.append((i, a[i]))
  mu_x += i
  mu_y += a[i]
  cov_xy += i * a[i]

mu_x /= n
mu_y /= n
cov_xy = cov_xy / n - mu_x * mu_y

sigma2_x = 0.0
for x, y in points:
  sigma2_x += (x - mu_x) ** 2

sigma2_x /= n

d = cov_xy / sigma2_x
b1 = mu_y - d * mu_x
c = sum([(b1 + i * d - points[i][1]) ** 2 for i in range(n)])
print("{:.7f} {:.7f}".format(b1, d))
print("{:.7f}".format(c))
0