QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#823479#9417. Palindromic PolygonKKT89WA 1ms3800kbC++174.3kb2024-12-21 02:04:102024-12-21 02:04:10

Judging History

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

  • [2024-12-21 02:04:10]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3800kb
  • [2024-12-21 02:04:10]
  • 提交

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;
        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 (k == i) break;
                nxt_r[k][v[i]] = i;
                if (v[k] == v[i]) break;
            }
        }
        vector<vector<ll>> dp(n, vector<ll>(n, -1));
        auto get_idx = [&](int l, int d) -> int {
            l += d;
            if (l >= n) l -= n;
            return l;
        };
        auto calc = [&](auto calc, int l, int d) -> ll {
            if (dp[l][d] != -1) {
                return dp[l][d];
            }
            dp[l][d] = 0;
            int r = get_idx(l, d);
            int nxt_l = l;
            for (int i = 1; i + d < n; ++i) {
                nxt_l -= 1;
                if (nxt_l == -1) nxt_l = n - 1;
                int uo = nxt_r[r][v[nxt_l]];
                if (uo == -1) continue;
                int cnt = uo - r;
                if (cnt < 0) cnt += n;
                if (cnt + i + d >= n) continue;
                ll add = 0;
                if (d == 0) {
                    add = area(p[l], p[nxt_l], p[uo]);
                } else {
                    add = area(p[l], p[r], p[uo]);
                    add += area(p[nxt_l], p[uo], p[l]);
                }
                dp[l][d] = max(dp[l][d], calc(calc, nxt_l, cnt + i + d) + add);
            }
            return dp[l][d];
        };
        for (int i = 0; i < n; ++i) {
            res = max(res, calc(calc, i, 0));
            for (int j = 0; j < n; ++j) {
                if (i == j or v[i] != v[j]) continue;
                int len = j - i;
                if (len < 0) len += n;
                res = max(res, calc(calc, i, len));
            }
        }
        cout << res << "\n";
    }
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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: 3572kb

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: 3664kb

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:

3800
1068
877
516
2668
3559
1165
3468
560
925
3502
696
3824
1746
2970
1826
613
2221
1130
4677
1900
1646
564
182
3203
6419
1070
3330
1024
765
142
3038
1615
9445
2122
271
1741
2561
1145
480
2094
5119
5458
2446
3929
2249
4378
4927
2356
1473
3152
1574
1990
1609
3367
2298
1459
2663
2617
2298
3986
215
420...

result:

wrong answer 1st numbers differ - expected: '3857', found: '3800'