QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#165821#6850. Amazing spacecraftPPP#WA 37ms6936kbC++175.5kb2023-09-05 22:03:332023-09-05 22:03:33

Judging History

This is the latest submission verdict.

  • [2023-09-05 22:03:33]
  • Judged
  • Verdict: WA
  • Time: 37ms
  • Memory: 6936kb
  • [2023-09-05 22:03:33]
  • Submitted

answer

#ifdef DEBUG
#define _GLIBCXX_DEBUG
#endif
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
int n;
const int maxN = 3e4 + 10;
ll x[maxN], y[maxN];
ll px[maxN], py[maxN];
int m;
ll X, Y, R;
void upd(vector<pair<ll,ll>>& F) {
    int pos = min_element(F.begin(), F.end()) - F.begin();
    rotate(F.begin(), F.begin() + pos, F.end());
}
int tp(pair<ll,ll>& a) {
    if (a.first > 0 || (a.first == 0 && a.second > 0)) return -1;
    return 1;
}
bool cmp(pair<ll,ll>& a, pair<ll,ll>& b) {
    if (tp(a) != tp(b)) return tp(a) < tp(b);
    return (a.first * b.second > a.second * b.first);
}
ll area(pair<ll,ll>& a, pair<ll,ll>& b, pair<ll,ll>& c) {
    return (b.first - a.first) * (c.second - a.second) - (b.second - a.second) * (c.first - a.first);
}
void solve() {
    cin >> n;
    vector<pair<ll,ll>> A, B;
    for (int i = 1; i <= n; i++) {
        cin >> x[i] >> y[i];
        x[i] *= -1;
        y[i] *= -1;
        A.emplace_back(x[i], y[i]);
    }
    cin >> m;
    for (int i = 1; i <= m; i++) {
        cin >> px[i] >> py[i];
        B.emplace_back(px[i], py[i]);
    }
    cin >> X >> Y >> R;
    upd(A);
    upd(B);
    vector<pair<ll,ll>> fin;
    fin.emplace_back(A[0].first + B[0].first, A[0].second + B[0].second);
    vector<pair<ll,ll>> vecs;
    for (int i = 0; i < A.size(); i++) {
        vecs.emplace_back(A[(i + 1) % A.size()].first - A[i].first, A[(i + 1) % A.size()].second - A[i].second);
    }
    for (int i = 0; i < B.size(); i++) {
        vecs.emplace_back(B[(i + 1) % B.size()].first - B[i].first, B[(i + 1) % B.size()].second - B[i].second);
    }
    sort(vecs.begin(), vecs.end(), cmp);
    for (int i = 0; i < vecs.size(); i++) {
        if (i > 0 && tp(vecs[i]) == tp(vecs[i - 1]) && vecs[i].first * vecs[i - 1].second == vecs[i].second * vecs[i - 1].first) {
            fin.back().first += vecs[i].first;
            fin.back().second += vecs[i].second;
        }
        else {
            fin.emplace_back(fin.back().first + vecs[i].first, fin.back().second + vecs[i].second);
        }
    }
    assert(fin.back() == fin[0]);
    fin.pop_back();
    for (auto& it : fin) {
        it.first -= X;
        it.second -= Y;
    }
    pair<ll,ll> zero = {0, 0};
    bool has_int = false;

    vector<pair<pair<ld,ld>,pair<int,int>>> CC;
    const int LINE = 0;
    const int CIRCLE = 1;
    const ld eps = 1e-6;
    bool has_inside = false;
    for (int i = 0; i < fin.size(); i++) {
        ll x1 = fin[i].first;
        ll y1 = fin[i].second;
        ll x2 = fin[(i + 1) % fin.size()].first;
        ll y2 = fin[(i + 1) % fin.size()].second;
        if (x1 * x1 + y1 * y1 <= R * R) {
            CC.emplace_back(make_pair(x1, y1), make_pair(LINE, i));
            has_inside = true;
        }
        ll dx = x2 - x1;
        ll dy = y2 - y1;
        __int128 A = dx * dx + dy * dy;
        __int128 B = 2 * dx * x1 + 2 * dy * y1;
        __int128 C = x1 * x1 + y1 * y1 - R * R;
        __int128 D = B * B - 4 * A * C;
        if (D < 0) continue;
        if (-B > 0 && C > 0) {
            if ((-B - 2 * A) <= 0 || (D >= (B + 2 * A) * (B + 2 * A))) {
                ld t = (-B - sqrtl(D)) / (2 * A);
                assert(t > -eps && t < 1 + eps);
                CC.emplace_back(make_pair(x1 + dx * t, y1 + dy * t), make_pair(CIRCLE, i));
            }
        }
        if (B <= 0 || D >= B * B) {
            if (2 * A + B > 0 && (2 * A + B) * (2 * A + B) > D) {
                ld t = (-B + sqrtl(D)) / (2 * A);
                CC.emplace_back(make_pair(x1 + dx * t, y1 + dy * t), make_pair(CIRCLE, i));
                assert(t > -eps && t < 1 + eps);
            }
        }
    }
    for (int i = 0; i < CC.size(); i++) {
        if (CC[i].second.first == CIRCLE) has_int = true;
    }
    const ld pi = acosl(-1.0);
    if (!has_int) {
        ll S = 0;
        for (int i = 1; i + 1 < fin.size(); i++) {
            S += area(fin[0], fin[i], fin[i + 1]);
        }
        ll my_ar = 0;
        for (int i = 0; i < fin.size(); i++) {
            my_ar += llabs(area(zero, fin[i], fin[(i + 1) % fin.size()]));
        }
        if (has_inside) {
            cout << fixed << setprecision(4) << (ld)llabs(S) / (2 * pi * R * R) << '\n';
        }
        else {
            if (my_ar == S) {
                cout << fixed << setprecision(4) << 1 << '\n';
            }
            else {
                cout << fixed << setprecision(4) << 0 << '\n';
            }
        }
        return;
    }
    ld ans = 0;
    for (int i = 0; i < CC.size(); i++) {
        auto t1 = CC[i];
        auto t2 = CC[(i + 1) % CC.size()];
        if (t1.second.first == CIRCLE && t2.second.first == CIRCLE && t1.second.second != t2.second.second) {
            //circle
            ld ang1 = atan2(t1.first.second, t1.first.first);
            ld ang2 = atan2(t2.first.second, t2.first.first);
            ang2 -= ang1;
            if (ang2 < 0) ang2 += 2 * pi;
            ans += ang2 * R * R / 2;
        }
        else {
            ld s = t2.first.second  * t1.first.first - t1.first.second * t2.first.first;
            ans += s / 2;
        }
    }
    cout << fixed << setprecision(4) << ans / (pi * R * R) << '\n';

}
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
#ifdef DEBUG
    freopen("input.txt", "r", stdin);
#endif
    int tst;
    cin >> tst;
    while (tst--) {
        solve();
    }
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 37ms
memory: 6936kb

input:

1122
11
-500 -114
-496 -490
-407 -500
462 -497
491 -243
492 -215
497 277
478 493
-415 498
-465 484
-495 176
15
-500 -11
-496 -403
-489 -497
-401 -499
-103 -499
447 -497
471 -476
477 -440
494 -290
488 367
482 451
454 489
3 499
-472 499
-497 469
713 -985 37
17
-496 17
-495 -430
-472 -492
-211 -500
76 ...

output:

0.0000
0.0000
0.0468
0.6318
0.0000
0.3651
0.0000
0.0861
0.0000
0.0000
0.0000
0.1941
0.0000
0.0000
0.8571
0.0000
0.0000
0
0.0000
0.0000
0.0000
0.0000
0.3607
0.0000
0.0000
0.0000
0.0000
0.2767
0.0000
0.5269
0.0000
0.0000
0.0000
0.0000
0.7206
0.0000
0.9219
0.0000
0.0000
0.0000
0.6407
1
0.0000
0.0000
0....

result:

wrong answer 1st lines differ - expected: '0.6789', found: '0.0000'