結果

問題 No.731 等差数列がだいすき
ユーザー WarToksWarToks
提出日時 2018-09-17 14:16:25
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 147 ms / 1,500 ms
コード長 434 bytes
コンパイル時間 531 ms
コンパイル使用メモリ 10,888 KB
実行使用メモリ 29,748 KB
最終ジャッジ日時 2023-09-25 09:21:56
合計ジャッジ時間 4,023 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 147 ms
29,384 KB
testcase_01 AC 134 ms
29,668 KB
testcase_02 AC 132 ms
29,524 KB
testcase_03 AC 134 ms
29,596 KB
testcase_04 AC 133 ms
29,636 KB
testcase_05 AC 136 ms
29,512 KB
testcase_06 AC 134 ms
29,724 KB
testcase_07 AC 133 ms
29,592 KB
testcase_08 AC 131 ms
29,604 KB
testcase_09 AC 132 ms
29,616 KB
testcase_10 AC 137 ms
29,724 KB
testcase_11 AC 133 ms
29,520 KB
testcase_12 AC 132 ms
29,612 KB
testcase_13 AC 137 ms
29,648 KB
testcase_14 AC 133 ms
29,532 KB
testcase_15 AC 135 ms
29,696 KB
testcase_16 AC 134 ms
29,588 KB
testcase_17 AC 134 ms
29,748 KB
testcase_18 AC 133 ms
29,656 KB
testcase_19 AC 135 ms
29,744 KB
testcase_20 AC 133 ms
29,652 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import numpy as np
n = int(input())
Y = []
meany = 0
for x in input().split():
    x = int(x)
    meany += x
    Y.append(x)
meany /= n
meanx = (n - 1) / 2
Y = np.array(Y) - meany
X = np.array(range(n)) - meanx

# print(X)

Sxy = 0
Sx2 = 0
for x, y in zip(X,Y):
    Sxy += x * y
    Sx2 += x ** 2
d = Sxy / Sx2 
b = meany - d * meanx
Y += meany
ai = b
cost = 0
for x in Y:
    cost += (x - ai) ** 2
    ai += d
print(b, d)
print(cost)
0