結果

問題 No.3672 Volume 3D
コンテスト
ユーザー titan23
提出日時 2026-09-04 23:10:46
言語 C++23
(gcc 15.3.0 + boost 1.92.0 + ACL)
コンパイル:
g++-15 -O2 -lm -std=c++23 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 158 ms / 2,000 ms
+ 527µs
コード長 2,197 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 2,043 ms
コンパイル使用メモリ 355,348 KB
実行使用メモリ 9,780 KB
最終ジャッジ日時 2026-09-04 23:11:13
合計ジャッジ時間 5,892 ms
ジャッジサーバーID
(参考情報)
judge1_0 / judge4_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 20
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

// #pragma GCC target("avx2")
// #pragma GCC optimize("O3")
// #pragma GCC optimize("unroll-loops")

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/hash_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

// #include <atcoder/all>
// using mint = atcoder::modint998244353;

using ll = long long;
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i)

// const ll dy[] = {-1, -1, -1, 0, 0, 1, 1, 1};
// const ll dx[] = {-1, 0, 1, -1, 1, -1, 0, 1};
const ll dy[] = {-1, 0, 0, 1};
const ll dx[] = {0, -1, 1, 0};

template <class T, class T1, class T2> bool isrange(T target, T1 low, T2 high) { return low <= target && target < high; }
template <class T, class U> T min(const T &t, const U &u) { return t < u ? t : u; }
template <class T, class U> T max(const T &t, const U &u) { return t < u ? u : t; }
template <class T, class U> bool chmin(T &t, const U &u) { if (t > u) { t = u; return true; } return false; }
template <class T, class U> bool chmax(T &t, const U &u) { if (t < u) { t = u; return true; } return false; }
template<class K, class V> using hash_map = gp_hash_table<K, V>;
template<class K> using hash_set = gp_hash_table<K, null_type>;

// #include "titan_cpplib/others/io.cpp"
// #include "titan_cpplib/others/print.cpp"
const double pi = 3.141592653589793238462643383279;


void solve() {
    double xa, ya, za, ra; cin >> xa >> ya >> za >> ra;
    double xb, yb, zb, rb; cin >> xb >> yb >> zb >> rb;
    if (ra > rb) {
        swap(xa, xb);
        swap(ya, yb);
        swap(za, zb);
        swap(ra, rb);
    }
    double d2 = (xa-xb)*(xa-xb) + (ya-yb)*(ya-yb) + (za-zb)*(za-zb);
    if (d2 > (ra+rb)*(ra+rb)) {
        cout << 0 << "\n";
        return;
    }
    if (d2 <= (ra-rb)*(ra-rb)) {
        cout << 4*pi*ra*ra*ra / 3 << "\n";
        return;
    }
    const double d = sqrt(d2);
    cout << (pi/(12*d)) * (ra+rb-d)*(ra+rb-d) * (d2 + (ra+rb)*d*2 - 3*(ra-rb)*(ra-rb)) << "\n";
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(15);
    cerr << fixed << setprecision(15);

    int t = 1;
    cin >> t;
    for (int i = 0; i < t; ++i) {
        solve();
    }

    return 0;
}
0