結果
| 問題 |
No.731 等差数列がだいすき
|
| ユーザー |
lam6er
|
| 提出日時 | 2025-03-20 18:49:32 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
AC
|
| 実行時間 | 44 ms / 1,500 ms |
| コード長 | 587 bytes |
| コンパイル時間 | 147 ms |
| コンパイル使用メモリ | 82,460 KB |
| 実行使用メモリ | 60,620 KB |
| 最終ジャッジ日時 | 2025-03-20 18:51:09 |
| 合計ジャッジ時間 | 1,794 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 18 |
ソースコード
n = int(input())
a = list(map(int, input().split()))
sum_a = sum(a)
sum_jm1 = n * (n - 1) // 2
sum_jm1_sq = (n - 1) * n * (2 * n - 1) // 6
sum_ajm = sum(a[i] * i for i in range(n))
denominator = n * sum_jm1_sq - sum_jm1 ** 2
d_numerator = n * sum_ajm - sum_jm1 * sum_a
b1_numerator = sum_jm1_sq * sum_a - sum_jm1 * sum_ajm
d = d_numerator / denominator
b1 = b1_numerator / denominator
cost = 0.0
for i in range(n):
expected = b1 + i * d
cost += (a[i] - expected) ** 2
# Print with sufficient precision
print("{0:.15f} {1:.15f}".format(b1, d))
print("{0:.15f}".format(cost))
lam6er