結果
| 問題 |
No.731 等差数列がだいすき
|
| ユーザー |
|
| 提出日時 | 2019-10-12 20:06:06 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 2 ms / 1,500 ms |
| コード長 | 549 bytes |
| コンパイル時間 | 570 ms |
| コンパイル使用メモリ | 70,592 KB |
| 実行使用メモリ | 5,248 KB |
| 最終ジャッジ日時 | 2024-11-29 02:44:04 |
| 合計ジャッジ時間 | 1,455 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 18 |
コンパイルメッセージ
main.cpp:5:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
5 | main()
| ^~~~
ソースコード
#include<iostream>
#include<iomanip>
using namespace std;
int N,A[1000];
main()
{
cin>>N;
for(int i=0;i<N;i++)cin>>A[i];
double xb=0,yb=0;
for(int i=0;i<N;i++)
{
xb+=i;
yb+=A[i];
}
xb/=N;
yb/=N;
double xs=0;
for(int i=0;i<N;i++)
{
xs+=(i-xb)*(i-xb);
}
xs/=N;
double EXY=0;
for(int i=0;i<N;i++)EXY+=i*A[i];
EXY/=N;
double Cov=EXY-xb*yb;
double d=Cov/xs;
double b=yb-d*xb;
cout<<fixed<<setprecision(16);
cout<<b<<" "<<d<<endl;
double ans=0;
for(int i=0;i<N;i++)
{
ans+=(A[i]-b-d*i)*(A[i]-b-d*i);
}
cout<<ans<<endl;
}