結果

問題 No.731 等差数列がだいすき
ユーザー minamiminami
提出日時 2019-04-04 16:53:48
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 123 ms / 1,500 ms
コード長 308 bytes
コンパイル時間 536 ms
コンパイル使用メモリ 10,632 KB
実行使用メモリ 29,964 KB
最終ジャッジ日時 2023-08-26 21:23:17
合計ジャッジ時間 6,531 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 120 ms
29,716 KB
testcase_01 AC 119 ms
29,844 KB
testcase_02 AC 116 ms
29,764 KB
testcase_03 AC 118 ms
29,812 KB
testcase_04 AC 122 ms
29,868 KB
testcase_05 AC 117 ms
29,712 KB
testcase_06 AC 116 ms
29,764 KB
testcase_07 AC 117 ms
29,720 KB
testcase_08 AC 118 ms
29,896 KB
testcase_09 AC 117 ms
29,836 KB
testcase_10 AC 117 ms
29,872 KB
testcase_11 AC 116 ms
29,756 KB
testcase_12 AC 116 ms
29,860 KB
testcase_13 AC 116 ms
29,732 KB
testcase_14 AC 120 ms
29,748 KB
testcase_15 AC 119 ms
29,816 KB
testcase_16 AC 117 ms
29,924 KB
testcase_17 AC 115 ms
29,908 KB
testcase_18 AC 119 ms
29,908 KB
testcase_19 AC 123 ms
29,952 KB
testcase_20 AC 121 ms
29,964 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import numpy as np
N = int(input())
y = list(map(int, input().split()))
x = [i for i in range(N)]
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 = 0
for i in range(N):
    cost += (y[i] - a*x[i] - b) ** 2
print(b, a)
print(cost)
0