結果

問題 No.731 等差数列がだいすき
コンテスト
ユーザー Pachicobue
提出日時 2018-09-07 21:33:00
言語 C++17
(gcc 15.2.0 + boost 1.89.0)
コンパイル:
g++-15 -O2 -lm -std=c++17 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 2 ms / 1,500 ms
コード長 1,025 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 1,399 ms
コンパイル使用メモリ 212,844 KB
実行使用メモリ 6,400 KB
最終ジャッジ日時 2026-06-07 01:11:53
合計ジャッジ時間 3,501 ms
ジャッジサーバーID
(参考情報)
judge1_1 / judge2_1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 18
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

//=================================
// Created on: 2018/09/07 21:23:40
//=================================
#include <bits/stdc++.h>
#define show(x) std::cerr << #x << " = " << x << std::endl
using ll = long long;
using ull = unsigned long long;
using ld = long double;
constexpr ll MOD = 1000000007LL;
template <typename T>
constexpr T INF = std::numeric_limits<T>::max() / 10;
std::mt19937 mt{std::random_device{}()};
int main()
{
    ll N;
    std::cin >> N;
    ld xy = 0, y = 0;
    std::vector<ld> a(N);
    for (ll i = 0; i < N; i++) {
        std::cin >> a[i];
        y += a[i], xy += i * a[i];
    }
    const ld x = N * (N - 1) / 2, xx = N * (N - 1) * (2 * N - 1) / 6;
    const ld d = (N * xy - x * y) / (N * xx - x * x), b1 = (xx * y - xy * x) / (N * xx - x * x);
    std::cout << std::fixed << std::setprecision(15) << b1 << " " << d << std::endl;
    ld c = 0;
    for (ll i = 0; i < N; i++) {
        const ld D = (d * i + b1 - a[i]);
        c += D * D;
    }
    std::cout << c << std::endl;
    return 0;
}
0