結果

問題 No.813 ユキちゃんの冒険
ユーザー te-shte-sh
提出日時 2020-01-12 16:10:15
言語 D
(dmd 2.105.2)
結果
TLE  
実行時間 -
コード長 2,420 bytes
コンパイル時間 2,166 ms
コンパイル使用メモリ 156,684 KB
実行使用メモリ 8,760 KB
最終ジャッジ日時 2023-09-04 04:35:55
合計ジャッジ時間 6,898 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 5 ms
4,504 KB
testcase_01 AC 16 ms
4,380 KB
testcase_02 AC 167 ms
4,376 KB
testcase_03 AC 255 ms
4,376 KB
testcase_04 AC 649 ms
4,376 KB
testcase_05 TLE -
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 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

// URL: https://yukicoder.me/problems/no/813

import std.algorithm, std.container, std.math, std.range, std.typecons, std.string;

version(unittest) {} else
void main()
{
  int n; io.getV(n);
  double p, q; io.getV(p, q);

  auto a1 = new double[](n), a2 = new double[](n);
  a1[] = 0; a1[0] = 1; a2[] = 0;
  auto ao = 0.0L, ai = 0.0L, ad = 0.0L;

  auto b1 = new double[](n), b2 = new double[](n);
  foreach (i; 0..10^^5) {
    foreach (j; 0..n) {
      if (j > 0)
        b1[j] = a1[j-1]*q + a2[j-1]*p;
      if (j < n-1)
        b2[j] = a1[j+1]*p + a2[j+1]*q;
      b1[0] = 0;
      b2[n-1] = 0;
    }
    auto bo = ao + a1[0]*p + a2[0]*q;
    auto bi = ai + a1[n-1]*q;
    auto bd = 0.0L;
    foreach (j; 0..n) bd += a1[j] + a2[j];
    bd *= 1-p-q;

    a1[] = b1[]; a2[] = b2[];
    ao = bo; ai = bi; ad = bd;
  }

  io.put(ao);
}

auto io = IO();

struct IO
{
  import std.algorithm, std.conv, std.format, std.meta, std.range, std.stdio, std.traits;

  dchar[] buf;
  auto sp = (new dchar[](0)).splitter;
  int precision = 10;
  string delimiter = " ";

  void nextLine()
  {
    stdin.readln(buf);
    sp = buf.splitter;
  }

  auto get(T)(ref T v)
  {
    if (sp.empty) nextLine();
    v = sp.front.to!T;
    sp.popFront();
  }

  auto getV(T...)(ref T v)
  {
    foreach (ref w; v) get(w);
  }

  auto getA(T)(size_t n, ref T v)
  if (hasAssignableElements!T)
  {
    v = new T(n);
    foreach (ref w; v) get(w);
  }

  auto getC(T...)(size_t n, ref T v)
  if (allSatisfy!(hasAssignableElements, T))
  {
    foreach (ref w; v)
      w = new typeof(w)(n);
    foreach (i; 0..n)
      foreach (ref w; v) get(w[i]);
  }

  auto getM(T)(size_t r, size_t c, ref T v)
  if (hasAssignableElements!T && hasAssignableElements!(ElementType!T))
  {
    v = new T(r);
    foreach (ref w; v) getA(c, w);
  }

  auto rangePop(R)(ref R r)
  {
    r.popFront();
    if (!r.empty) write(delimiter);
  }

  auto putA(T)(T v)
  {
    static if (isInputRange!T && !isSomeString!T)
      for (auto w = v; !w.empty; rangePop(w)) putA(w.front);
    else if (isFloatingPoint!T)
      writef(format("%%.%df", precision), v);
    else
      write(v);
  }

  auto put(T...)(T v)
  {
    foreach (i, w; v) {
      putA(w);
      if (i < v.length-1) write(delimiter);
    }
    writeln;
  }

  auto putB(S, T)(bool c, S t, T f)
  {
    if (c)
      put(t);
    else
      put(f);
  }

  auto dbg(T...)(T v)
  {
    stderr.writeln(v);
  }
}
0