結果

問題 No.731 等差数列がだいすき
ユーザー knk
提出日時 2018-09-07 21:57:35
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 967 bytes
コンパイル時間 1,376 ms
コンパイル使用メモリ 168,772 KB
実行使用メモリ 6,824 KB
最終ジャッジ日時 2024-11-29 13:06:27
合計ジャッジ時間 7,175 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1 WA * 2
other WA * 18
権限があれば一括ダウンロードができます

ソースコード

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 rate = 1.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;
    }
    rate = 1.0/(1+ep);
    b -= rate * db/n;
    d -= rate * dd/n;
    rate -= 1.0/max_ep;
    //if (ep%1000==0) cout << b << " " << d << endl;
  }
  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