結果

問題 No.764 浮動点
ユーザー zimphazimpha
提出日時 2019-03-08 02:47:41
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 3 ms / 1,500 ms
コード長 1,453 bytes
コンパイル時間 621 ms
コンパイル使用メモリ 69,204 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-05 19:32:57
合計ジャッジ時間 2,268 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <vector>

const double pi = acos(-1.0);

int main() {
  int n, L0;
  scanf("%d%d", &n, &L0);
  std::vector<int> L(n + 1);
  std::vector<std::pair<int, int>> prefix(n + 1), suffix(n + 1);
  for (int i = 0; i <= n; ++i) {
    scanf("%d", &L[i]);
  }
  prefix[0] = {L[0], L[0]};
  for (int i = 1; i <= n; ++i) {
    prefix[i].first = prefix[i - 1].first + L[i];
    prefix[i].second = std::max(prefix[i - 1].second, L[i]);
  }
  suffix[n] = {L[n], L[n]};
  for (int i = n - 1; i >= 0; --i) {
    suffix[i].first = suffix[i + 1].first + L[i];
    suffix[i].second = std::max(suffix[i + 1].second, L[i]);
  }
  auto area = [&L0] (double r1, double r2) {
    if (r1 + r2 <= L0) return 0.0;
    if (L0 + r2 <= r1) return r2 * r2 * pi;
    if (L0 + r1 <= r2) return r1 * r1 * pi;

    double t1 = acos((r1 * r1 + L0 * L0 - r2 * r2) / (2 * r1 * L0)) * 2;
    double t2 = acos((r2 * r2 + L0 * L0 - r1 * r1) / (2 * r2 * L0)) * 2;

    double res = 0;
    res += 0.5 * r1 * r1 * (t1 - sin(t1));
    res += 0.5 * r2 * r2 * (t2 - sin(t2));
    return res;
  };

  for (int i = 1; i <= n; ++i) {
    double R1 = prefix[i - 1].first;
    double r1 = std::max(2 * prefix[i - 1].second - R1, 0.);
    double R2 = suffix[i].first;
    double r2 = std::max(2 * suffix[i].second - R2, 0.);
    printf("%.10f\n", area(R1, R2) - area(R1, r2) - area(r1, R2) + area(r1, r2));
  }
  return 0;
}
0