結果

問題 No.731 等差数列がだいすき
ユーザー kurimupykurimupy
提出日時 2020-06-15 16:08:03
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 141 ms / 1,500 ms
コード長 357 bytes
コンパイル時間 110 ms
コンパイル使用メモリ 10,668 KB
実行使用メモリ 29,740 KB
最終ジャッジ日時 2023-09-16 10:26:27
合計ジャッジ時間 4,811 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 139 ms
29,640 KB
testcase_01 AC 133 ms
29,620 KB
testcase_02 AC 133 ms
29,516 KB
testcase_03 AC 131 ms
29,632 KB
testcase_04 AC 141 ms
29,704 KB
testcase_05 AC 132 ms
29,712 KB
testcase_06 AC 132 ms
29,732 KB
testcase_07 AC 134 ms
29,548 KB
testcase_08 AC 129 ms
29,688 KB
testcase_09 AC 132 ms
29,672 KB
testcase_10 AC 130 ms
29,596 KB
testcase_11 AC 130 ms
29,588 KB
testcase_12 AC 128 ms
29,640 KB
testcase_13 AC 129 ms
29,644 KB
testcase_14 AC 131 ms
29,576 KB
testcase_15 AC 131 ms
29,688 KB
testcase_16 AC 130 ms
29,592 KB
testcase_17 AC 130 ms
29,620 KB
testcase_18 AC 130 ms
29,740 KB
testcase_19 AC 128 ms
29,660 KB
testcase_20 AC 130 ms
29,708 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import numpy as np
INF = 10 ** 10

N = int(input())
X = np.arange(N,dtype = np.int64)
Y = np.array(input().split(),dtype = np.int64)

median_Y = Y.sum()/N
median_X = (N - 1)/2

Sx = ((X - median_X) ** 2).sum()/N
Sxy = ((X - median_X)*(Y - median_Y)).sum()/N
b1 = Sxy/Sx
b0 = median_Y - median_X*b1
cost = ((Y - b0 - b1*X)**2).sum()
print(b0,b1)
print(cost)
0