結果

問題 No.764 浮動点
ユーザー te-shte-sh
提出日時 2020-02-12 21:46:51
言語 D
(dmd 2.106.1)
結果
AC  
実行時間 3 ms / 1,500 ms
コード長 3,593 bytes
コンパイル時間 3,157 ms
コンパイル使用メモリ 165,052 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-06-22 05:04:38
合計ジャッジ時間 4,281 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,812 KB
testcase_01 AC 1 ms
6,944 KB
testcase_02 AC 1 ms
6,940 KB
testcase_03 AC 1 ms
6,944 KB
testcase_04 AC 2 ms
6,940 KB
testcase_05 AC 2 ms
6,940 KB
testcase_06 AC 3 ms
6,944 KB
testcase_07 AC 1 ms
6,940 KB
testcase_08 AC 3 ms
6,940 KB
testcase_09 AC 2 ms
6,944 KB
testcase_10 AC 2 ms
6,940 KB
testcase_11 AC 2 ms
6,944 KB
testcase_12 AC 2 ms
6,944 KB
testcase_13 AC 3 ms
6,944 KB
testcase_14 AC 2 ms
6,940 KB
testcase_15 AC 3 ms
6,940 KB
testcase_16 AC 3 ms
6,940 KB
testcase_17 AC 3 ms
6,940 KB
testcase_18 AC 3 ms
6,944 KB
testcase_19 AC 3 ms
6,948 KB
testcase_20 AC 2 ms
6,940 KB
testcase_21 AC 3 ms
6,940 KB
testcase_22 AC 3 ms
6,940 KB
testcase_23 AC 2 ms
6,944 KB
testcase_24 AC 2 ms
6,940 KB
testcase_25 AC 1 ms
6,944 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Main.d(108): Deprecation: function `Main.IO!(makeGlobal, makeGlobal).IO.put!("{}", int).put.putMain!(c, int).putMain` function requires a dual-context, which is deprecated
Main.d-mixin-96(96):        instantiated from here: `putMain!(c, int)`
Main.d(38):        instantiated from here: `put!("{}", int)`
Main.d(108): Deprecation: function `Main.IO!(makeGlobal, makeGlobal).IO.put!("{}", double).put.putMain!(c, double).putMain` function requires a dual-context, which is deprecated
Main.d-mixin-96(96):        instantiated from here: `putMain!(c, double)`
Main.d(42):        instantiated from here: `put!("{}", double)`

ソースコード

diff #

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

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

version(unittest) {} else
void main()
{
  int N; io.getV(N);
  double[] L; io.getC(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]);

  auto integral(double a, double x)
  {
    if ((a-x).abs < 1e-11) return a^^2*PI/2;
    return x*sqrt(a^^2-x^^2) + a^^2*asin(x/a);
  }

  auto calc(double r1, double r2)
  {
    if (r1+r2 < L0) {
      return 0.0;
    } else if (r1+L0 < r2) {
      return PI*r1^^2;
    } else if (r2+L0 < r1) {
      return PI*r2^^2;
    } else {
      auto x = (L0^^2+r1^^2-r2^^2)/(L0*2);
      return integral(r2, x-L0)-integral(r2, -r2)+integral(r1, r1)-integral(r1, x);
    }
  }

  io.put(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);
    io.put(calc(a, c)-calc(a, d)-calc(b, c)+calc(b, d));
  }
  io.put(0);
}

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

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

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

auto io = IO!()();
import std.stdio;
struct IO(alias IN = stdin, alias OUT = stdout)
{
  import std.conv, std.format, std.meta, std.traits, core.stdc.stdlib;

  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); }
  template getS(E...)
  {
    auto getS(T)(size_t n, ref T v)
    { v = new T(n); foreach (ref w; v) foreach (e; E) mixin("get(w."~e~");"); }
  }

  const struct PutConf
  {
    bool newline = true, flush, exit;
    string floatFormat = "%.10f", delimiter = " ";
  }

  auto put(alias conf = "{}", T...)(T v)
  { mixin("const PutConf c = "~conf~"; putMain!c(v);"); }
  auto putB(alias conf = "{}", S, T)(bool c, S t, T f)
  { if (c) put(t); else put(f); }
  auto putRaw(T...)(T v) { OUT.write(v); OUT.writeln; }

  private
  {
    dchar[] buf;
    auto sp = (new dchar[](0)).splitter;
    void nextLine() { IN.readln(buf); sp = buf.splitter; }
    auto get(T)(ref T v) { if (sp.empty) nextLine(); v = sp.front.to!T; sp.popFront(); }

    auto putMain(PutConf c, T...)(T v)
    {
      foreach (i, w; v) {
        putOne!c(w);
        if (i < v.length-1) OUT.write(c.delimiter);
      }
      static if (c.newline) OUT.writeln;
      static if (c.flush) OUT.flush();
      static if (c.exit) exit(0);
    }
    auto putOne(PutConf c, T)(T v)
    {
      static if (isInputRange!T && !isSomeString!T) putRange!c(v);
      else if (isFloatingPoint!T) OUT.write(format(c.floatFormat, v));
      else OUT.write(v);
    }
    auto putRange(PutConf c, T)(T v)
    {
      auto w = v;
      while (!w.empty) {
        putOne!c(w.front); w.popFront();
        if (!w.empty) OUT.write(c.delimiter);
      }
    }
  }
}
0