QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#598652#9434. Italian Cuisineucup-team3584#WA 21ms3688kbC++204.7kb2024-09-28 22:50:232024-09-28 22:50:24

Judging History

你现在查看的是最新测评结果

  • [2024-09-28 22:50:24]
  • 评测
  • 测评结果:WA
  • 用时:21ms
  • 内存:3688kb
  • [2024-09-28 22:50:23]
  • 提交

answer

#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;

mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
ll myRand(ll B) { return (ull)rng() % B; }

// 整数幾何
typedef ll Integer;
const Integer eps = 0;
inline constexpr int sgn(Integer a, Integer b = 0) { return (a - b < -eps) ? -1 : (a - b > eps) ? 1 : 0; }
inline constexpr int arg_type(Integer x, Integer y) { return y < 0 ? 2 : x < 0 ? 1 : 0; }
struct Point {
    Integer x, y;
    constexpr Point(Integer x = 0, Integer y = 0) : x(x), y(y) {}
    constexpr Point operator+() const noexcept { return *this; }
    constexpr Point operator-() const noexcept { return Point(-x, -y); }
    constexpr Point operator+(const Point &p) const { return Point(x + p.x, y + p.y); }
    constexpr Point operator-(const Point &p) const { return Point(x - p.x, y - p.y); }
    constexpr Point &operator+=(const Point &p) { return x += p.x, y += p.y, *this; }
    constexpr Point &operator-=(const Point &p) { return x -= p.x, y -= p.y, *this; }
    constexpr Point &operator*=(const Integer &k) { return x *= k, y *= k, *this; }
    constexpr Point operator*(const Integer &k) { return Point(x * k, y * k); }
    constexpr bool operator==(const Point &r) const noexcept { return r.x == x and r.y == y; }
    constexpr Integer dot(const Point &r) const { return x * r.x + y * r.y; }
    constexpr Integer cross(const Point &r) const { return x * r.y - y * r.x; }
    constexpr Integer norm2() const { return x * x + y * y; }
    // 比較関数
    constexpr bool lex_comp(const Point &r) const { return sgn(x, r.x) < 0 || (sgn(x, r.x) == 0 and sgn(y, r.y) < 0); }
    constexpr bool arg_comp(const Point &r) const {
        int L = arg_type(x, y), R = arg_type(r.x, r.y);
        if (L != R) return L < R;
        Integer crs = (*this).cross(r);
        if (crs == 0) return abs(x) + abs(y) < abs(r.x) + abs(r.y);
        else return crs > 0;
    }
    // IO
    friend istream &operator>>(istream &is, Point &p) {
        is >> p.x >> p.y;
        return (is);
    }
    friend ostream &operator<<(ostream &os, Point &p) { return os << p.x << " " << p.y; }
};

Integer dot(Point a, Point b) { return a.dot(b); }
Integer cross(Point a, Point b) { return a.cross(b); }

bool is_in_triangle(vector<Point> v, Point p) {
    bool in = false;
    for (int i = 0; i < v.size(); ++i) {
        Point a = v[i], b = v[(i + 1) % v.size()];
        a -= p, b -= p;
        if (a.y > b.y) std::swap(a, b);
        if (sgn(a.y) <= 0 and 0 < sgn(b.y) and sgn(cross(a, b)) < 0) in ^= 1;
    }
    return in;
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int q;
    cin >> q;
    while (q--) {
        int n;
        cin >> n;
        Point r;
        ll rr;
        cin >> r >> rr;
        vector<Point> p(n);
        for (int i = 0; i < n; ++i) {
            cin >> p[i];
        }
        for (int i = 0; i < n; ++i) {
            p.push_back(p[i]);
        }
        for (int i = 0; i < n; ++i) {
            p.push_back(p[i]);
        }
        auto area = [&](Point a, Point b, Point c) -> ll {
            b -= a, c -= a;
            ll bx = b.x, by = b.y, cx = c.x, cy = c.y;
            return abs(bx * cy - cx * by);
        };

        ll res = 0, sum = 0;
        for (int i = 0, j = 0; i < n; ++i) {
            j = max(j, i + 2);
            while (j < p.size()) {
                vector<Point> vs = {p[i], p[j - 1], p[j]};
                if (is_in_triangle(vs, r)) break;
                auto check1 = [&](Point a, Point b) -> bool {
                    b -= a;
                    // sqrt(b.x * b.x + b.y * b.y) <= rr
                    return b.x * b.x + b.y * b.y <= rr * rr;
                };
                auto check2 = [&]() -> bool {
                    ll uo = abs(cross(r - vs[0], vs[2] - vs[0]));
                    Point b = vs[2] - vs[0];
                    // uo / dist(vs[2], vs[0]) <= rr
                    // uo <= rr * sqrt(b.x * b.x + b.y * b.y)
                    using int128_t = __int128_t;
                    int128_t u = (int128_t)uo * (int128_t)uo;
                    int128_t uu = rr * rr * (int128_t)(b.x * b.x + b.y * b.y);
                    return u <= uu;
                };
                if (check1(r, vs[0])) break;
                if (check1(r, vs[2])) break;
                if (check2()) break;
                sum += area(p[i], p[j - 1], p[j]);
                j += 1;
            }
            res = max(res, sum);
            if (j > i + 2) {
                sum -= area(p[i], p[i + 1], p[j - 1]);
            }
        }
        cout << res << "\n";
    }
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3588kb

input:

3
5
1 1 1
0 0
1 0
5 0
3 3
0 5
6
2 4 1
2 0
4 0
6 3
4 6
2 6
0 3
4
3 3 1
3 0
6 3
3 6
0 3

output:

5
24
0

result:

ok 3 number(s): "5 24 0"

Test #2:

score: 0
Accepted
time: 0ms
memory: 3688kb

input:

1
6
0 0 499999993
197878055 -535013568
696616963 -535013568
696616963 40162440
696616963 499999993
-499999993 499999993
-499999993 -535013568

output:

0

result:

ok 1 number(s): "0"

Test #3:

score: -100
Wrong Answer
time: 21ms
memory: 3620kb

input:

6666
19
-142 -128 26
-172 -74
-188 -86
-199 -157
-200 -172
-199 -186
-195 -200
-175 -197
-161 -188
-144 -177
-127 -162
-107 -144
-90 -126
-87 -116
-86 -104
-89 -97
-108 -86
-125 -80
-142 -74
-162 -72
16
-161 -161 17
-165 -190
-157 -196
-154 -197
-144 -200
-132 -200
-128 -191
-120 -172
-123 -163
-138...

output:

5093
2862
2539
668
3535
7421
4883
5711
5624
1034
2479
3920
4372
2044
4996
5070
2251
4382
4175
1489
1154
3231
4038
1631
5086
14444
1692
6066
687
1512
4849
5456
2757
8341
8557
8235
1013
5203
10853
6042
6300
4480
2303
2728
1739
2187
3385
4266
6322
909
4334
1518
948
5036
1449
2376
3180
4810
1443
1786
47...

result:

wrong answer 2nd numbers differ - expected: '3086', found: '2862'