QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#599127#9417. Palindromic Polygonucup-team3584#WA 0ms3788kbC++234.7kb2024-09-29 01:41:222024-09-29 01:41:23

Judging History

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

  • [2024-09-29 01:41:23]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3788kb
  • [2024-09-29 01:41:22]
  • 提交

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;
                    if (v[k] == v[i]) break;
                    nxt_r[k][v[i]] = i;
                }
            }
            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: 3788kb

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: -100
Wrong Answer
time: 0ms
memory: 3532kb

input:

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

output:

4000000000000000000

result:

wrong answer 1st numbers differ - expected: '8000000000000000000', found: '4000000000000000000'