結果

問題 No.76 回数の期待値で練習
ユーザー te-shte-sh
提出日時 2016-09-08 17:28:39
言語 D
(dmd 2.107.1)
結果
AC  
実行時間 44 ms / 5,000 ms
コード長 719 bytes
コンパイル時間 2,089 ms
コンパイル使用メモリ 160,752 KB
実行使用メモリ 18,596 KB
最終ジャッジ日時 2023-09-02 22:00:18
合計ジャッジ時間 2,661 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,372 KB
testcase_01 AC 44 ms
18,596 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import std.algorithm, std.array, std.container, std.range, std.bitmanip;
import std.numeric, std.math, std.bigint, std.random, core.bitop;
import std.string, std.regex, std.conv, std.stdio, std.typecons;

const real[] pi = [
  0, 0.08333333333333326, 0.16666666666666674, 0.2500000000000001,
  0.08333333333333298, 0.24999999999999983, 0.16666666666666718
];

void main()
{
  auto t = readln.chomp.to!size_t;
  auto ni = iota(t).map!(_ => readln.chomp.to!int).array;

  auto maxN = ni.reduce!(max);
  auto memo = new real[](maxN + 1);

  foreach (i; 1..maxN + 1) {
    memo[i] = 1;
    foreach (d; 1..6 + 1)
      memo[i] += i - d <= 0 ? 0 : memo[i - d] * pi[d];
  }

  foreach (n; ni)
    writefln("%.6f", memo[n]);
}
0