結果

問題 No.731 等差数列がだいすき
ユーザー PachicobuePachicobue
提出日時 2018-09-07 21:33:00
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 1,500 ms
コード長 1,025 bytes
コンパイル時間 2,684 ms
コンパイル使用メモリ 200,404 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-19 12:43:20
合計ジャッジ時間 3,825 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

//=================================
// 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