結果

問題 No.731 等差数列がだいすき
ユーザー prd_xxxprd_xxx
提出日時 2018-09-07 22:51:45
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 21 ms / 1,500 ms
コード長 377 bytes
コンパイル時間 113 ms
コンパイル使用メモリ 10,732 KB
実行使用メモリ 8,320 KB
最終ジャッジ日時 2023-08-19 21:36:37
合計ジャッジ時間 1,574 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 18 ms
7,860 KB
testcase_01 AC 18 ms
7,956 KB
testcase_02 AC 18 ms
7,952 KB
testcase_03 AC 19 ms
7,768 KB
testcase_04 AC 17 ms
7,848 KB
testcase_05 AC 18 ms
7,848 KB
testcase_06 AC 19 ms
8,320 KB
testcase_07 AC 19 ms
7,780 KB
testcase_08 AC 20 ms
7,944 KB
testcase_09 AC 19 ms
7,852 KB
testcase_10 AC 18 ms
8,204 KB
testcase_11 AC 17 ms
7,832 KB
testcase_12 AC 18 ms
7,776 KB
testcase_13 AC 18 ms
7,864 KB
testcase_14 AC 18 ms
7,708 KB
testcase_15 AC 21 ms
7,764 KB
testcase_16 AC 18 ms
7,844 KB
testcase_17 AC 20 ms
7,916 KB
testcase_18 AC 19 ms
8,204 KB
testcase_19 AC 17 ms
8,300 KB
testcase_20 AC 16 ms
8,280 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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