結果

問題 No.731 等差数列がだいすき
ユーザー RTIA1227RTIA1227
提出日時 2018-09-07 21:39:07
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 2 ms / 1,500 ms
コード長 1,158 bytes
コンパイル時間 2,184 ms
コンパイル使用メモリ 85,368 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-19 17:37:38
合計ジャッジ時間 3,160 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include<iostream>
#include<vector>
#include<algorithm>
#include<functional>
#include<queue>
#include<stack>
#include<set>
#include<climits>
#include<cstdlib>
#include<cmath>
#include<string>
#include<iomanip>

using namespace std;

#define INF 1 << 29
#define LL long long int

LL const MOD = 1000000007;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);

    double n;
    cin >> n;
    vector<double> a(n);
    for(int i = 0; i < n; i++){
        cin >> a[i];
    }

    double x = 0.0;
    double y = 0.0;
    double xy = 0.0;
    double xx = 0.0;

    for(int i = 0; i < n; i++){
        x += (double)i;
        y += a[i];
        xy += a[i]*((double)i);
        xx += ((double)i)*((double)i);
    }

    double first = ((xx*y)-(xy*x))/(((double)n)*xx - (x*x) );
    double d = ((((double)n)*xy)-(x*y))/(((double)n)*xx - (x*x));

    double c = 0.0;

    for(int i = 0; i < n; i++){
        c += (a[i] - (((double)i)*d + first))*(a[i] - (((double)i)*d + first));
    }

    cout << fixed;
    cout << setprecision(17) << first << " ";
    cout << setprecision(17) << d << endl;
    cout << setprecision(17) << c << endl;
    
    return 0;
}
0