結果
| 問題 | No.731 等差数列がだいすき |
| コンテスト | |
| ユーザー |
koyopro
|
| 提出日時 | 2019-12-22 00:51:45 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0 + boost 1.89.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,982 bytes |
| 記録 | |
| コンパイル時間 | 1,420 ms |
| コンパイル使用メモリ | 161,288 KB |
| 実行使用メモリ | 6,948 KB |
| 最終ジャッジ日時 | 2024-09-13 06:35:04 |
| 合計ジャッジ時間 | 9,282 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 1 WA * 17 |
ソースコード
#include "bits/stdc++.h"
using namespace std;
#define int long long
#define FOR(i, a, b) for(int i=(a);i<(b);i++)
#define RFOR(i, a, b) for(int i=(b-1);i>=(a);i--)
#define REP(i, n) for(int i=0; i<(n); i++)
#define RREP(i, n) for(int i=(n-1); i>=0; i--)
#define ALL(a) (a).begin(),(a).end()
#define UNIQUE_SORT(l) sort(ALL(l)); l.erase(unique(ALL(l)), l.end());
#define CONTAIN(a, b) find(ALL(a), (b)) != (a).end()
#define array2(type, x, y) array<array<type, y>, x>
#define vector2(type) vector<vector<type> >
#define out(...) printf(__VA_ARGS__)
typedef pair<int, int> pos;
int pos::*x = &pos::first;
int pos::*y = &pos::second;
int dxy[] = {0, 1, 0, -1, 0};
/*================================*/
int N;
float A[1000];
double cost(double b, double d) {
double diff = 0;
REP(i, N) {
double an = b + d * i;
diff += pow(A[i] - an, 2);
}
return diff;
}
signed main()
{
#if DEBUG
std::ifstream in("input.txt");
std::cin.rdbuf(in.rdbuf());
#endif
cin >> N;
REP(i, N) cin >> A[i];
double b = 0, d = 0, c = FLT_MAX;
double base = pow(10, 5);
REP(ip, 2) REP(i, 25) REP(jp, 2) REP(j, 25) {
double tb = 1.0 * base / (1<<i);
if (ip == 1) tb *= -1;
double td = 1.0 * base / (1<<j);
if (jp == 1) td *= -1;
double tc = cost(tb, td);
if (tc < c) {
b = tb;
d = td;
c = tc;
}
}
float diff = base;
REP(i, base) {
REP(j, 2) {
double tb = b + pow(-1, j) * diff;
double tc = cost(tb, d);
if (tc < c) {
b = tb;
c = tc;
}
}
REP(j, 2) {
double td = d + pow(-1, j) * diff;
double tc = cost(b, td);
if (tc < c) {
d = td;
c = tc;
}
}
diff *= 0.9997;
}
out("%.14f %.14f\n%.14f\n", b, d, c);
return 0;
}
koyopro