結果

問題 No.764 浮動点
ユーザー te-shte-sh
提出日時 2018-12-12 17:35:26
言語 D
(dmd 2.107.1)
結果
TLE  
実行時間 -
コード長 2,592 bytes
コンパイル時間 2,110 ms
コンパイル使用メモリ 156,048 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-03 21:39:21
合計ジャッジ時間 5,562 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 108 ms
4,380 KB
testcase_01 TLE -
testcase_02 -- -
testcase_03 -- -
testcase_04 -- -
testcase_05 -- -
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 #

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

auto rdsp(){return readln.splitter;}
void pick(R,T)(ref R r,ref T t){t=r.front.to!T;r.popFront;}
void readV(T...)(ref T t){auto r=rdsp;foreach(ref v;t)pick(r,v);}
void readC(T...)(size_t n,ref T t){foreach(ref v;t)v=new typeof(v)(n);foreach(i;0..n){auto r=rdsp;foreach(ref v;t)pick(r,v[i]);}}

void main()
{
  int n; readV(n);
  double[] l; readC(n+2, l);

  auto l0 = l[0], lc = l.cumulativeSum;
  auto ll = new double[](n+2), lr = new double[](n+2);
  ll[1] = l[1];
  foreach (i; 2..n+2) ll[i] = max(ll[i-1], l[i]);
  lr[n+1] = l[n+1];
  foreach_reverse (i; 1..n+1) lr[i] = max(lr[i+1], l[i]);

  writeln(0);
  foreach (i; 2..n) {
    auto a = lc[1..i+1], b = max(2*ll[i]-a, 0);
    auto c = lc[i+1..$], d = max(2*lr[i+1]-c, 0);
    auto a2 = a^^2, b2 = b^^2, c2 = c^^2, d2 = d^^2;

    double f(double x)
    {
      auto ay = 0.0L, by = 0.0L, cy = 0.0L, dy = 0.0L;
      if (-a < x && x < a) ay = a2-x^^2;
      if (-b < x && x < b) by = b2-x^^2;
      if (l0-c < x && x < l0+c) cy = c2-(x-l0)^^2;
      if (l0-d < x && x < l0+d) dy = d2-(x-l0)^^2;
      return max(0.0L, min(ay, cy).sqrt-max(by, dy).sqrt);
    }

    writefln("%.7f", integrateDE((x) => f(x), -a, l0+c, 1e-6)*2);
  }
  writeln(0);
}

class CumulativeSum(T)
{
  size_t n;
  T[] s;

  this(T[] a)
  {
    n = a.length;
    s = new T[](n+1);
    s[0] = T(0);
    foreach (i; 0..n) s[i+1] = s[i] + a[i];
  }

  T opSlice(size_t l, size_t r) { return s[r]-s[l]; }
  size_t opDollar() { return n; }
}
auto cumulativeSum(T)(T[] a) { return new CumulativeSum!T(a); }

double integrateDE(double delegate(double) f, double a, double b, double eps = 1e-8)
{
  import std.math;

  const auto c = asin(1.0), tm = 10.0;

  double delegate(double) x, g;
  if (!a.isInfinity && !b.isInfinity) {
    x = (double t) => (b+a)/2 + (b-a)/2*tanh(c*sinh(t));
    g = (double t) => c*(b-a)/2*cosh(t)/cosh(c*sinh(t))^^2;
  } else if (!a.isInfinity) {
    x = (double t) => a + exp(c*sinh(t));
    g = (double t) => c*cosh(t)*exp(c*sinh(t));
  } else if (!b.isInfinity) {
    x = (double t) => b - exp(c*sinh(-t));
    g = (double t) => c*cosh(t)*exp(c*sinh(-t));
  } else {
    x = (double t) => sinh(c*sinh(t));
    g = (double t) => c*cosh(t)*cosh(c*sinh(t));
  }

  auto s = 0.0, h = 1.0/c;
  auto cnt = 0;
  for (;;) {
    auto i = 0.0;
    for (auto t = 0.0; t < tm; t = t > 0 ? -t : -t+h) {
      auto di = f(x(t)) * g(t) * h;
      if (!di.isNaN) i += di;
    }
    if (abs(i-s) < abs(i)*eps) return i;
    s = i;
    h /= 2;
  }
}
0