結果

問題 No.731 等差数列がだいすき
コンテスト
ユーザー prd_xxx
提出日時 2018-09-07 22:51:45
言語 Python3
(3.14.3 + numpy 2.4.4 + scipy 1.17.1)
コンパイル:
python3 -mpy_compile _filename_
実行:
python3 _filename_
結果
AC  
実行時間 98 ms / 1,500 ms
コード長 377 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 437 ms
コンパイル使用メモリ 20,952 KB
実行使用メモリ 15,448 KB
最終ジャッジ日時 2026-05-23 11:34:18
合計ジャッジ時間 3,579 ms
ジャッジサーバーID
(参考情報)
judge1_0 / judge3_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 18
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

N = int(input())
src = list(map(int,input().split()))
mu_x = (N-1) / 2
mu_y = sum(src) / N

sq_sigma_x = 0
for x in range(N):
    sq_sigma_x += (x - mu_x)**2
sq_sigma_x /= N

e_xy = sum([x*y for x,y in enumerate(src)]) / N
cov = e_xy - mu_x*mu_y

d = cov / sq_sigma_x
bi = mu_y - d*mu_x
cost = 0
for i,a in enumerate(src):
    cost += (a - (bi+i*d))**2

print(bi,d)
print(cost)
0