結果

問題 No.731 等差数列がだいすき
ユーザー りあんりあん
提出日時 2018-09-07 08:13:58
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 1,500 ms
コード長 736 bytes
コンパイル時間 1,892 ms
コンパイル使用メモリ 200,312 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-16 18:09:40
合計ジャッジ時間 3,213 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
const int M = 1000000007;

int main() {
    int n;
    cin >> n;
    assert(2 <= n && n <= 1000);
    vector<int> a(n);
    double s1 = (n - 1) * n / 2;
    double s2 = (n - 1) * n * (2 * n - 1) / 6;
    double sa1 = 0, sa2 = 0;
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
        assert(0 <= a[i] && a[i] <= 100000);
        sa1 += a[i];
        sa2 += a[i] * i;
    }
    double b = (s2 * sa1 - s1 * sa2) / (n * s2 - s1 * s1);
    double d = (-s1 * sa1 + n * sa2) / (n * s2 - s1 * s1);
    double c = 0;
    for (int i = 0; i < n; ++i)
        c += (a[i] - (b + d * i)) * (a[i] - (b + d * i));

    cout << setprecision(9) << b << " " << d << "\n" << c << "\n";
    return 0;
}
0