結果

問題 No.764 浮動点
ユーザー nebukuro09nebukuro09
提出日時 2018-12-13 19:01:30
言語 D
(dmd 2.105.2)
結果
AC  
実行時間 15 ms / 1,500 ms
コード長 1,672 bytes
コンパイル時間 1,929 ms
コンパイル使用メモリ 160,144 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-03 21:40:43
合計ジャッジ時間 3,182 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

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

struct Circle {
    real x;
    real y;
    real r;
}

real intersection(Circle c1, Circle c2) {
    if (c1.r > c2.r) {
        swap(c1, c2);
    }

    real d = sqrt((c1.x - c2.x)^^2 + (c1.y - c2.y)^^2);

    if (d >= c1.r + c2.r) {
        return 0;
    }

    if (d <= c2.r-c1.r) {
        return c1.r * c1.r * PI;
    }

    real a1 = c1.r * c1.r * acos((d * d + c1.r * c1.r - c2.r * c2.r) / (2 * d * c1.r));
    real a2 = c2.r * c2.r * acos((d * d + c2.r * c2.r - c1.r * c1.r) / (2 * d * c2.r));
    real a3 = 0.5 * sqrt((-d + c1.r + c2.r) * (d + c1.r - c2.r) * (d - c1.r + c2.r) * (d + c1.r + c2.r));

    return a1 + a2 - a3;
}

real calc(Circle big1, Circle small1, Circle big2, Circle small2) {
    real a1 = intersection(big1, big2);
    real a2 = intersection(small1, big2);
    real a3 = intersection(small2, big1);
    real a4 = intersection(small1, small2);
    return (a1 - a2 - a3 + a4);
}

void main() {
    auto N = readln.chomp.to!int;
    auto P = readln.chomp.to!long;
    auto L = (N+1).iota.map!(_ => readln.chomp.to!long).array;

    foreach (i; 0..N) {
        auto s1 = L[0..i+1].sum;
        auto m1 = L[0..i+1].reduce!max;
        auto s2 = L[i+1..$].sum;
        auto m2 = L[i+1..$].reduce!max;
        auto big1 = Circle(0, 0, s1);
        auto small1 = Circle(0, 0, max(0, m1*2-s1));
        auto big2 = Circle(P, 0, s2);
        auto small2 = Circle(P, 0, max(0, m2*2-s2));
        writefln("%.9f", calc(big1, small1, big2, small2));
    }
}
0