結果
| 問題 |
No.731 等差数列がだいすき
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2022-10-15 05:15:53 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 2 ms / 1,500 ms |
| コード長 | 770 bytes |
| コンパイル時間 | 2,051 ms |
| コンパイル使用メモリ | 195,332 KB |
| 最終ジャッジ日時 | 2025-02-08 06:06:18 |
|
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 18 |
ソースコード
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
int main(){
cin.tie(0);
ios::sync_with_stdio(0);
using ld = long double;
int N; cin >> N;
vector<pair<ld,ld>> p(N);
rep(i,N) {
p[i].first = i;
cin >> p[i].second;
}
ld X = 0, Y = 0, XY = 0, XX = 0;
for(auto [x, y] : p) {
X += x;
Y += y;
XY += x * y;
XX += x * x;
}
ld a = (N * XY - X * Y) / (N * XX - X * X);
ld b = (XX * Y - XY * X) / (N * XX - X * X);
ld e = 0;
rep(i,N) {
auto [x, y] = p[i];
ld y2 = a * i + b;
e += (y - y2) * (y - y2);
}
cout << fixed << setprecision(20) << b << " " << a << "\n" << e << endl;
}