結果

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

テストケース

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

ソースコード

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;
  double rate = 1.0;
  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/2;
    dd += pdd/2;
    pdb=db;
    pdd=dd;
    b -= rate * db/n * 0.1;
    d -= rate * dd/n * 0.1;
    rate -= 0.5/max_ep;
  }
  cout << b << " " << d << endl;
  double cost = 0;
  for (ul i=0; i<n; ++i) {
    double diff = b+d*i-a[i];
    cost += diff*diff;
  }
  cout << cost << endl;
  return 0;
}
0