結果
問題 | No.731 等差数列がだいすき |
ユーザー |
![]() |
提出日時 | 2018-09-07 21:39:07 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 2 ms / 1,500 ms |
コード長 | 1,158 bytes |
コンパイル時間 | 1,243 ms |
コンパイル使用メモリ | 84,144 KB |
実行使用メモリ | 5,248 KB |
最終ジャッジ日時 | 2024-11-29 11:54:29 |
合計ジャッジ時間 | 1,957 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 18 |
ソースコード
#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 intLL 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;}