結果

問題 No.731 等差数列がだいすき
ユーザー knkknk
提出日時 2018-09-07 22:03:01
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 955 bytes
コンパイル時間 1,317 ms
コンパイル使用メモリ 168,852 KB
実行使用メモリ 13,952 KB
最終ジャッジ日時 2024-05-07 01:44:33
合計ジャッジ時間 6,777 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ul;
typedef signed long long ll;
ul over = 1000000007;

mt19937 mt(time(nullptr));
// uniform_int_distribution< int > rand_int(0, 10) // rand[0, 10] inclusive

int main(void)
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed;
  int n;
  cin >> n;
  vector< double > a(n);
  for (int i=0; i<n; ++i) {
    cin >> a[i];
  }
  double b=a[0], d=(a[n-1]-a[0])/(n-1);
  double pdb=0, pdd=0;
  ul max_ep = 100000000/n;
  for (ul ep=0; ep<max_ep; ++ep) {
    double db=0, dd=0;
    for (int i=0; i<n; ++i) {
      db += 2*(b+d*i-a[i]);
      dd += 2*(b+d*i-a[i]) * i;
    }
    db += pdb*0.9;
    dd += pdd*0.9;
    pdb=db;
    pdd=dd;
    double rate = 0.01;
    b -= rate * db/n;
    d -= rate * dd/n;
  }
  cout << b << " " << d << endl;
  double cost = 0;
  for (ul i=0; i<n; ++i) {
    cost += (b + d*i - a[i]) * (b + d*i - a[i]);
  }
  cout << cost << endl;
  return 0;
}
0