結果

問題 No.764 浮動点
ユーザー te-shte-sh
提出日時 2018-12-12 16:28:26
言語 D
(dmd 2.105.2)
結果
TLE  
実行時間 -
コード長 2,496 bytes
コンパイル時間 1,890 ms
コンパイル使用メモリ 153,708 KB
実行使用メモリ 4,504 KB
最終ジャッジ日時 2023-09-03 21:38:58
合計ジャッジ時間 37,452 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
4,380 KB
testcase_01 AC 5 ms
4,376 KB
testcase_02 AC 21 ms
4,380 KB
testcase_03 AC 476 ms
4,376 KB
testcase_04 TLE -
testcase_05 AC 561 ms
4,380 KB
testcase_06 TLE -
testcase_07 AC 650 ms
4,376 KB
testcase_08 TLE -
testcase_09 AC 735 ms
4,376 KB
testcase_10 TLE -
testcase_11 AC 822 ms
4,376 KB
testcase_12 TLE -
testcase_13 TLE -
testcase_14 TLE -
testcase_15 TLE -
testcase_16 TLE -
testcase_17 TLE -
testcase_18 TLE -
testcase_19 TLE -
testcase_20 TLE -
testcase_21 TLE -
testcase_22 TLE -
testcase_23 TLE -
testcase_24 TLE -
testcase_25 AC 164 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

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", integrate!double((x) => f(x), -a, l0+c, 1e-5)*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); }

T integrate(T)(T delegate(T) f, T lo, T hi, T eps = 1e-8)
{
  import std.math;

  const auto th = eps / 1e-14;

  T rec(T x0, T x6, T y0, T y6, int d)
  {
    const auto a = sqrt(2.0/3.0), b = 1.0 / sqrt(5.0);
    auto x3 = (x0+x6)/2, y3 = f(x3), h = (x6-x0)/2;
    auto x1 = x3-a*h, x2 = x3-b*h, x4 = x3+b*h, x5 = x3+a*h;
    auto y1 = f(x1), y2 = f(x2), y4 = f(x4), y5 = f(x5);
    auto i1 = (y0 + y6 + (y2 + y4) * 5) * (h/6);
    auto i2 = ((y0 + y6) * 77 + (y1 + y5) * 432 + (y2 + y4) * 625 + y3 * 672) * (h/1470);
    if (x3 + h == x3 || d > 50) return 0.0;
    if (d > 4 && th + (i1 - i2) == th) return i2;
    return rec(x0, x1, y0, y1, d+1) + rec(x1, x2, y1, y2, d+1) +
           rec(x2, x3, y2, y3, d+1) + rec(x3, x4, y3, y4, d+1) +
           rec(x4, x5, y4, y5, d+1) + rec(x5, x6, y5, y6, d+1);
  }

  return rec(lo, hi, f(lo), f(hi), 0);
}
0