結果
問題 | No.731 等差数列がだいすき |
ユーザー |
|
提出日時 | 2018-09-22 17:09:03 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 2 ms / 1,500 ms |
コード長 | 806 bytes |
コンパイル時間 | 1,659 ms |
コンパイル使用メモリ | 169,040 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-07-18 09:00:21 |
合計ジャッジ時間 | 2,363 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 18 |
ソースコード
#include <bits/stdc++.h>using namespace std;using ll = long long;int main() {cin.tie(0);ios::sync_with_stdio(false);ll n;cin >> n;vector<ll> a(n);for (int i = 0; i < n; i++) cin >> a[i];ll A = 0, A2 = 0, sum_i2 = 0;for (int i = 0; i < n; i++) {A += a[i];A2 += i * a[i];sum_i2 += i * i;}ll hoge = 2 * sum_i2 - (n - 1) * n / 2 * (n - 1);ll foo = 2 * A2 - A * (n - 1);double d = (double)foo / hoge;double b = (double)A / n - d * (n - 1) / 2;cout << fixed << setprecision(15) << b << " " << d << endl;double cost = 0;for (int i = 0; i < n; i++) {double x = b + d * i;x -= a[i];cost += x * x;}cout << fixed << setprecision(15) << cost << endl;return 0;}