結果

問題 No.731 等差数列がだいすき
ユーザー maspymaspy
提出日時 2020-01-02 15:30:04
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 497 ms / 1,500 ms
コード長 434 bytes
コンパイル時間 129 ms
コンパイル使用メモリ 12,544 KB
実行使用メモリ 44,712 KB
最終ジャッジ日時 2024-05-02 06:32:31
合計ジャッジ時間 10,925 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 445 ms
43,952 KB
testcase_01 AC 442 ms
44,340 KB
testcase_02 AC 438 ms
44,084 KB
testcase_03 AC 446 ms
44,336 KB
testcase_04 AC 449 ms
43,948 KB
testcase_05 AC 450 ms
44,084 KB
testcase_06 AC 497 ms
44,080 KB
testcase_07 AC 477 ms
44,456 KB
testcase_08 AC 486 ms
43,992 KB
testcase_09 AC 489 ms
43,944 KB
testcase_10 AC 469 ms
44,332 KB
testcase_11 AC 446 ms
44,332 KB
testcase_12 AC 453 ms
44,336 KB
testcase_13 AC 437 ms
43,956 KB
testcase_14 AC 439 ms
44,340 KB
testcase_15 AC 445 ms
44,712 KB
testcase_16 AC 461 ms
43,960 KB
testcase_17 AC 457 ms
44,592 KB
testcase_18 AC 440 ms
44,324 KB
testcase_19 AC 456 ms
44,332 KB
testcase_20 AC 442 ms
43,952 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

import numpy as np

# いわゆる最小二乗法

N = int(readline())
x = np.arange(N)
y = np.array(read().split(),np.int64)

mu_x = x.mean(); mu_y = y.mean()

a = np.dot(x - mu_x, y - mu_y) / np.dot(x - mu_x, x - mu_x)

fit_y = a * (x - mu_x) + mu_y
error = ((y - fit_y) ** 2).sum()

print(fit_y[0], a)
print(error)
0