結果

問題 No.53 悪の漸化式
ユーザー alpha_virginisalpha_virginis
提出日時 2016-09-12 22:51:26
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 5,000 ms
コード長 938 bytes
コンパイル時間 1,588 ms
コンパイル使用メモリ 163,008 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-10 19:18:40
合計ジャッジ時間 2,696 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>

long double f(long double p, long double pp) {
  return (19 * p - 12 * pp) / 4;
}

int main() {
  long double memo[128] = {};
  memo[0] = 4;
  memo[1] = 3;
  // for(int i = 2; i <= 100; ++i) {
  //   printf("%3d : %.20lf\n", i, (double)(memo[i] = f(memo[i-1], memo[i-2])));
  // }

  long double diff[128]; // diff[i] = ax[i] - 4 * ax[i-1] => ax[i] = diff[i] + 4 * ax[i-1]
  diff[1] = -13;
  for(int i = 2; i < 128; ++i) {
    diff[i] = diff[i-1] * 3 / 4;
  }
  // for(int i = 1; i <= 100; ++i) {
  //   printf("%lf %lf\n", (double)(memo[i] - 4 * memo[i-1]), (double)diff[i]);
  // }

  for(int i = 2; i < 128; ++i) {
    memo[i] = diff[i] + 4 * memo[i-1];
  }
  for(int i = 2; i < 128; ++i) {
    memo[i] = memo[i-1] * 3 / 4;
  }
  // for(int i = 2; i <= 100; ++i) {
  //   printf("%3d : %.20lf\n", i, (double)(memo[i]));
  // }
  int n;
  scanf("%d", &n);
  printf("%.30lf\n", (double)memo[n]);

  return 0;
}
0