結果
問題 |
No.731 等差数列がだいすき
|
ユーザー |
![]() |
提出日時 | 2019-04-04 17:08:50 |
言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
結果 |
AC
|
実行時間 | 526 ms / 1,500 ms |
コード長 | 421 bytes |
コンパイル時間 | 286 ms |
コンパイル使用メモリ | 12,544 KB |
実行使用メモリ | 44,464 KB |
最終ジャッジ日時 | 2024-12-26 00:19:24 |
合計ジャッジ時間 | 12,096 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 18 |
ソースコード
import numpy as np N = int(input()) y = list(map(int, input().split())) x = [i for i in range(N)] def least_squares(x, y): n = len(x) var_x = np.var(x) mu_x = np.mean(x) mu_y = np.mean(y) cov = sum((x-mu_x)*(y-mu_y)) / n a = cov / var_x b = mu_y - a*mu_x cost = sum((_y - a*_x - b) ** 2 for _x, _y in zip(x, y)) return a, b, cost a, b, c = least_squares(x, y) print(b, a) print(c)