結果
| 問題 |
No.731 等差数列がだいすき
|
| コンテスト | |
| ユーザー |
ei1333333
|
| 提出日時 | 2018-09-07 22:43:10 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 888 ms / 1,500 ms |
| コード長 | 1,216 bytes |
| コンパイル時間 | 1,821 ms |
| コンパイル使用メモリ | 199,620 KB |
| 最終ジャッジ日時 | 2025-01-06 13:01:26 |
|
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 18 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
using int64 = long long;
#define double long double
int main() {
int N, A[1000];
cin >> N;
for(int i = 0; i < N; i++) cin >> A[i];
tuple< double, double, double > ret(1e30, 1e30, 1e30);
{
double left = -1e10, right = 1e10;
auto check2 = [&](double real_a) {
auto check = [&](double real_d) {
double cost = 0.0;
for(int j = 0; j < N; j++) {
double v = real_a + j * real_d;
cost += (A[j] - v) * (A[j] - v);
}
ret = min(ret, make_tuple(cost, real_a, real_d));
return cost;
};
double low = -1e5, high = 1e5;
for(int j = 0; j < 300; j++) {
double latte = (low * 2 + high) / 3;
double malta = (low + high * 2) / 3;
if(check(latte) < check(malta)) high = malta;
else low = latte;
}
return check(low);
};
for(int i = 0; i < 300; i++) {
double aa = (left * 2 + right) / 3;
double bb = (left + right * 2) / 3;
if(check2(aa) < check2(bb)) right = bb;
else left = aa;
}
}
cout << fixed << setprecision(10) << get< 1 >(ret) << " " << get< 2 >(ret) << endl << get< 0 >(ret) << endl;
}
ei1333333