結果

問題 No.731 等差数列がだいすき
ユーザー zekezeke
提出日時 2019-12-01 15:47:21
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 1,500 ms
コード長 3,118 bytes
コンパイル時間 708 ms
コンパイル使用メモリ 97,120 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-05-01 07:36:21
合計ジャッジ時間 1,475 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,816 KB
testcase_01 AC 2 ms
6,944 KB
testcase_02 AC 2 ms
6,940 KB
testcase_03 AC 2 ms
6,944 KB
testcase_04 AC 2 ms
6,940 KB
testcase_05 AC 2 ms
6,940 KB
testcase_06 AC 2 ms
6,940 KB
testcase_07 AC 2 ms
6,940 KB
testcase_08 AC 2 ms
6,940 KB
testcase_09 AC 2 ms
6,940 KB
testcase_10 AC 2 ms
6,940 KB
testcase_11 AC 1 ms
6,944 KB
testcase_12 AC 2 ms
6,944 KB
testcase_13 AC 2 ms
6,944 KB
testcase_14 AC 2 ms
6,940 KB
testcase_15 AC 1 ms
6,940 KB
testcase_16 AC 2 ms
6,940 KB
testcase_17 AC 2 ms
6,940 KB
testcase_18 AC 2 ms
6,940 KB
testcase_19 AC 2 ms
6,944 KB
testcase_20 AC 2 ms
6,944 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

/*
    Author:zeke
    
    pass System Test!
    GET AC!!
*/
#include <iostream>
#include <queue>
#include <vector>
#include <iostream>
#include <vector>
#include <string>
#include <cassert>
#include <algorithm>
#include <functional>
#include <cmath>
#include <queue>
#include <set>
#include <stack>
#include <deque>
#include <map>
#include <iomanip>
#include <utility>
#include <stack>
using ll = long long;
using ld = long double;
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define rep3(var, min, max) for (ll(var) = (min); (var) < (max); ++(var))
#define repi3(var, min, max) for (ll(var) = (max)-1; (var) + 1 > (min); --(var))
#define Mp(a, b) make_pair((a), (b))
#define F first
#define S second
#define Icin(s) \
    ll(s);      \
    cin >> (s);
#define Scin(s) \
    ll(s);      \
    cin >> (s);
template <class T>
bool chmax(T &a, const T &b)
{
    if (a < b)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T &a, const T &b)
{
    if (b < a)
    {
        a = b;
        return 1;
    }
    return 0;
}
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef vector<V> VV;
typedef vector<P> VP;
ll mod = 1e9 + 7;
ll INF = 1e18;

using matrix = vector<V>;
struct Matrix
{
    static const int maxn = 105;
    ll A[maxn][maxn];
    int n;

    Matrix(int n_) : n(n_)
    {
        for (int i = 0; i < n; ++i)
            for (int j = 0; j < n; ++j)
                A[i][j] = 0;
    }

    Matrix operator*(const Matrix &o) const
    {
        Matrix ret(n);
        for (int i = 0; i < n; ++i)
            for (int j = 0; j < n; ++j)
                for (int k = 0; k < n; ++k)
                {
                    ll c = A[i][k] * o.A[k][j] % mod;
                    ret.A[i][j] = (ret.A[i][j] + c) % mod;
                }
        return ret;
    }

    static Matrix identity(int n)
    {
        Matrix ret(n);
        for (int i = 0; i < n; ++i)
            ret.A[i][i] = 1;
        return ret;
    }

    Matrix operator^(long long k) const
    {
        Matrix ret = identity(n);
        Matrix a = *this;
        while (k)
        {
            if (k & 1)
                ret = ret * a;
            a = a * a;
            k /= 2;
        }
        return ret;
    }
};
void lsm(vector<ld> x, vector<ld> y, int N, long double *a0, long double *a1)
{
    int i;
    double A00 = 0, A01 = 0, A02 = 0, A11 = 0, A12 = 0;

    for (i = 0; i < N; i++)
    {
        A00 += 1.0;
        A01 += x[i];
        A02 += y[i];
        A11 += x[i] * x[i];
        A12 += x[i] * y[i];
    }

    *a0 = (A02 * A11 - A01 * A12) / (A00 * A11 - A01 * A01);
    *a1 = (A00 * A12 - A01 * A02) / (A00 * A11 - A01 * A01);
}
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n;
    cin>>n;
    vector<ld> vec(n);
    rep(i, n) cin >> vec[i];
    vector<ld> vec2(n);
    rep(i, n) vec2[i] = i;
    ld x = 0;
    ld y=0;
    lsm(vec2,vec,n,&x,&y);
    cout <<setprecision(20)<< x << " " << y << endl;
    ld res=0;
    rep(i,n){
        res+=pow(((x+y*i)-vec[i]),2);
    }
    cout<<res<<endl;
}
0