結果

問題 No.731 等差数列がだいすき
ユーザー dnishdnish
提出日時 2018-09-22 16:03:12
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,364 bytes
コンパイル時間 1,495 ms
コンパイル使用メモリ 164,348 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-25 11:06:30
合計ジャッジ時間 3,165 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 15 ms
4,380 KB
testcase_04 AC 38 ms
4,380 KB
testcase_05 AC 15 ms
4,380 KB
testcase_06 WA -
testcase_07 AC 30 ms
4,376 KB
testcase_08 AC 37 ms
4,380 KB
testcase_09 AC 46 ms
4,376 KB
testcase_10 WA -
testcase_11 AC 4 ms
4,376 KB
testcase_12 AC 26 ms
4,376 KB
testcase_13 AC 35 ms
4,380 KB
testcase_14 AC 41 ms
4,376 KB
testcase_15 WA -
testcase_16 AC 28 ms
4,380 KB
testcase_17 WA -
testcase_18 WA -
testcase_19 AC 63 ms
4,380 KB
testcase_20 AC 63 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include "bits/stdc++.h"

#define REP(i, n, N) for(ll i=(n); i<(N); i++)
#define RREP(i, n, N) for(ll i=(N-1); i>=n; i--)
#define CK(n, a, b) ((a)<=(n)&&(n)<(b))
#define ALL(v) (v).begin(),(v).end()
#define MCP(a, b) memcpy(b,a,sizeof(b))
#define p(s) cout<<(s)<<endl
#define p2(a, b) cout<<(a)<<" "<<(b)<<endl
#define v2(T) vector<vector<T>>
typedef long long ll;
using namespace std;
const ll mod = 1e9 + 7;
const ll inf = 1e18;

int N;
int a[2010];
double b,d;

double dist(double b0, double mid){
    double diff=0;
    REP(i,0,N){
        diff += (b0 + i*mid - a[i]) * (b0 + i*mid - a[i]);
    }
    return diff;
}
double search(double mid){
    double lb=-1e9,ub=1e9;
    double mid1, mid2;
    REP(i,0,100){
        mid1 = (lb*2 +ub) / 3.;
        mid2 = (lb + ub*2) / 3.;
        if(dist(mid, mid1) >= dist(mid, mid2)) lb = mid1;
        else ub=mid2;
    }
    d = mid1;
    return dist(mid, mid1);
}
int main() {
    cin>>N;
    REP(i,0,N) cin>>a[i];
    REP(i,0,N-1){
        d += a[i+1] - a[i];
    }
    d /= (N-1);
    double lb=-1e9,ub=1e9;
    double mid1, mid2;
    REP(i,0,100){
        mid1 = (lb*2 +ub) / 3.;
        mid2 = (lb + ub*2) / 3.;
        if(search(mid1) >= search(mid2)) lb = mid1;
        else ub=mid2;
    }
    b = mid1;
    double dist = search(b);
    printf("%.7lf %.7lf\n", b, d);
    printf("%.7lf\n", dist);
    return 0;
}
0