結果

問題 No.731 等差数列がだいすき
ユーザー t98slidert98slider
提出日時 2023-07-31 02:19:17
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 662 bytes
コンパイル時間 1,841 ms
コンパイル使用メモリ 165,384 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-18 03:20:34
合計ジャッジ時間 2,935 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 WA -
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 AC 2 ms
5,376 KB
testcase_12 AC 2 ms
5,376 KB
testcase_13 AC 2 ms
5,376 KB
testcase_14 WA -
testcase_15 AC 2 ms
5,376 KB
testcase_16 AC 2 ms
5,376 KB
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll = long long;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    vector<ll> vec(n);
    for(auto &&v : vec) cin >> v;
    double xa = (n - 1) / 2, ya = (double)accumulate(vec.begin(), vec.end(), 0ll) / n;
    double V = 0, D = 0;
    for(int i = 0; i < n; i++){
        V += (i - xa) * (vec[i] - ya);
        D += (i - xa) * (i - xa);
    }
    double a = V / D, b = ya - a * xa, ans = 0;
    for(int i = 0; i < n; i++){
        double v = a * i + b - vec[i];
        ans += v * v;
    }
    cout << fixed << setprecision(15) << b << ' ' << a << '\n' << ans << '\n';
}
0