結果

問題 No.731 等差数列がだいすき
ユーザー qibqib
提出日時 2023-03-31 00:24:23
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 41 ms / 1,500 ms
コード長 501 bytes
コンパイル時間 284 ms
コンパイル使用メモリ 81,496 KB
実行使用メモリ 53,264 KB
最終ジャッジ日時 2023-10-22 07:23:37
合計ジャッジ時間 2,118 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 40 ms
53,260 KB
testcase_01 AC 39 ms
53,260 KB
testcase_02 AC 37 ms
53,260 KB
testcase_03 AC 41 ms
53,264 KB
testcase_04 AC 39 ms
53,264 KB
testcase_05 AC 38 ms
53,264 KB
testcase_06 AC 39 ms
53,264 KB
testcase_07 AC 39 ms
53,264 KB
testcase_08 AC 40 ms
53,264 KB
testcase_09 AC 39 ms
53,264 KB
testcase_10 AC 40 ms
53,264 KB
testcase_11 AC 37 ms
53,264 KB
testcase_12 AC 39 ms
53,260 KB
testcase_13 AC 38 ms
53,264 KB
testcase_14 AC 39 ms
53,264 KB
testcase_15 AC 40 ms
53,264 KB
testcase_16 AC 40 ms
53,264 KB
testcase_17 AC 40 ms
53,264 KB
testcase_18 AC 41 ms
53,264 KB
testcase_19 AC 40 ms
53,264 KB
testcase_20 AC 40 ms
53,264 KB
権限があれば一括ダウンロードができます

ソースコード

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