結果
| 問題 |
No.731 等差数列がだいすき
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2018-09-07 21:33:00 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 24 ms / 1,500 ms |
| コード長 | 1,025 bytes |
| コンパイル時間 | 2,082 ms |
| コンパイル使用メモリ | 197,672 KB |
| 最終ジャッジ日時 | 2025-01-06 12:53:58 |
|
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 18 |
ソースコード
//=================================
// Created on: 2018/09/07 21:23:40
//=================================
#include <bits/stdc++.h>
#define show(x) std::cerr << #x << " = " << x << std::endl
using ll = long long;
using ull = unsigned long long;
using ld = long double;
constexpr ll MOD = 1000000007LL;
template <typename T>
constexpr T INF = std::numeric_limits<T>::max() / 10;
std::mt19937 mt{std::random_device{}()};
int main()
{
ll N;
std::cin >> N;
ld xy = 0, y = 0;
std::vector<ld> a(N);
for (ll i = 0; i < N; i++) {
std::cin >> a[i];
y += a[i], xy += i * a[i];
}
const ld x = N * (N - 1) / 2, xx = N * (N - 1) * (2 * N - 1) / 6;
const ld d = (N * xy - x * y) / (N * xx - x * x), b1 = (xx * y - xy * x) / (N * xx - x * x);
std::cout << std::fixed << std::setprecision(15) << b1 << " " << d << std::endl;
ld c = 0;
for (ll i = 0; i < N; i++) {
const ld D = (d * i + b1 - a[i]);
c += D * D;
}
std::cout << c << std::endl;
return 0;
}