QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#599133#9417. Palindromic Polygonucup-team3584#WA 1ms3688kbC++234.7kb2024-09-29 01:43:182024-09-29 01:43:19

Judging History

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

  • [2024-09-29 01:43:19]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3688kb
  • [2024-09-29 01:43:18]
  • 提交

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 arg_type(Integer x, Integer y) { return y < 0 ? 2 : x < 0 ? 1 : 0; }
struct Point {
    Integer x, y;
    constexpr explicit 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) const { 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; }
};

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int q;
    cin >> q;
    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);
    };
    while (q--) {
        int n, m;
        cin >> n;
        vector<int> v(n);
        for (int i = 0; i < n; ++i) {
            cin >> v[i];
        }
        {
            auto z = v;
            sort(z.begin(), z.end());
            z.erase(unique(z.begin(), z.end()), z.end());
            m = z.size();
            for (int i = 0; i < n; ++i) {
                v[i] = lower_bound(z.begin(), z.end(), v[i]) - z.begin();
            }
        }
        vector<Point> p(n);
        for (int i = 0; i < n; ++i) {
            cin >> p[i].x >> p[i].y;
        }

        ll res = 0;
        for (int _ = 0; _ < 2; ++_) {
            reverse(v.begin(), v.end());
            reverse(p.begin(), p.end());

            vector<vector<int>> nxt_r(n);
            for (int i = 0; i < n; ++i) {
                nxt_r[i].resize(m);
                std::fill(nxt_r[i].begin(), nxt_r[i].end(), -1);
            }
            for (int i = 0; i < n; ++i) {
                for (int j = 0, k = i; j < n; ++j) {
                    k -= 1;
                    if (k == -1) k = n - 1;
                    nxt_r[k][v[i]] = i;
                    if (v[k] == v[i]) break;
                }
            }
            vector<vector<ll>> dp(n, vector<ll>(n, -1));
            for (int i = 0; i < n; ++i) {
                dp[i][i] = 0;
            }
            auto valid = [&](int l, int r, int x) -> bool {
                if (l <= r) {
                    if (l <= x and x <= r) return false;
                    else return true;
                } else {
                    if (r < x and x < l) return true;
                    else return false;
                }
            };
            auto calc = [&](auto calc, int l, int r) -> ll {
                if (dp[l][r] != -1) return dp[l][r];
                dp[l][r] = 0;
                for (int i = 0, j = l; i < n; ++i) {
                    j -= 1;
                    if (j == -1) j = n - 1;
                    if (j == r) break;
                    int k = nxt_r[r][v[j]];
                    if (k == -1) continue;
                    if (valid(j, r, k)) {
                        dp[l][r] = max(dp[l][r], calc(calc, j, k) + area(p[l], p[r], p[j]) + area(p[j], p[k], p[r]));
                    }
                }
                return dp[l][r];
            };
            for (int i = 0; i < n; ++i) {
                for (int j = 0, k = i; j < n; ++j) {
                    k += 1;
                    if (k == n) k = 0;
                    if (v[i] == v[k] and dp[i][k] == -1) {
                        calc(calc, i, k);
                    }
                    res = max(res, dp[i][k]);
                    for (int l = 0, kk = i; l < j; ++l) {
                        kk += 1;
                        if (kk == n) kk = 0;
                        res = max(res, dp[i][k] + area(p[i], p[kk], p[k]));
                    }
                }
            }
        }
        cout << res << "\n";
    }
}

详细

Test #1:

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

input:

3
8
2 4 2 4 3 4 5 3
2 3
0 6
-3 3
-3 0
-2 -3
1 -5
3 -3
4 0
3
1 2 3
0 0
1 0
0 1
3
1 1 1
0 0
1 0
0 1

output:

84
0
1

result:

ok 3 number(s): "84 0 1"

Test #2:

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

input:

1
4
1000000000 1000000000 1000000000 1000000000
-1000000000 -1000000000
1000000000 -1000000000
1000000000 1000000000
-1000000000 1000000000

output:

8000000000000000000

result:

ok 1 number(s): "8000000000000000000"

Test #3:

score: -100
Wrong Answer
time: 1ms
memory: 3624kb

input:

129
10
604040473 604040473 287094217 682965575 70435786 287094217 604040473 287094217 682965575 92620053
-193 -184
-200 -200
-125 -169
-120 -157
-120 -145
-124 -139
-137 -136
-155 -149
-172 -163
-187 -177
5
346787871 346787871 113397429 113397429 346787871
-173 -181
-186 -166
-200 -195
-194 -200
-17...

output:

3857
1068
1239
516
2668
3559
1165
3468
560
925
3502
696
3824
1746
2970
1826
1011
2221
1130
4677
1900
1646
564
273
3203
6572
1070
3330
1024
765
142
3038
1615
9445
2122
385
1741
2561
1145
480
2094
5119
5458
2446
3929
2249
4378
4927
2356
1473
3152
1574
1990
1609
3367
2298
1459
2663
2617
2298
4048
232
5...

result:

wrong answer 3rd numbers differ - expected: '877', found: '1239'