QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#609430#9417. Palindromic PolygonUESTC_OldEastWest#WA 1ms3584kbC++172.2kb2024-10-04 12:55:432024-10-04 12:55:44

Judging History

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

  • [2024-10-04 12:55:44]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3584kb
  • [2024-10-04 12:55:43]
  • 提交

answer

#include<bits/stdc++.h>
#define int long long
using namespace std;
const int mod = 998244353;
inline void cmax(int &x, const int &y) {
    if (x < y) x = y;
}
struct Point {
    int x, y;
    friend Point operator-(const Point&x, const Point&y) {
        return {x.x - y.x, x.y - y.y};
    }
    friend int operator^(const Point&x, const Point&y) {
        return x.x * y.y - y.x * x.y;
    }
};

inline int Area(const Point &x, const Point&y, const Point&z) {
    Point A = y - x;
    Point B = z - x;
    return abs(A ^ B);
}

inline void Solve() {
    int n, k; cin >> n;
    vector<int> a, tv; a.reserve(n * 2);
    for (int i = 1, x; i <= n; i++) cin >> x, a.push_back(x), tv.push_back(x);
    sort(tv.begin(), tv.end());
    tv.erase(unique(tv.begin(), tv.end()), tv.end());
    for (int i = 0; i < n; i++) a[i] = lower_bound(tv.begin(), tv.end(), a[i]) - tv.begin();
    vector<vector<int>>lst(2 * n, vector<int>(2 * n, -1));
    for (int i = 0; i < n; i++) a.push_back(a[i]);
    for (int i = 0; i < 2 * n; i++) {
        for (int j = 0; j < tv.size(); j++) {
            if (j == a[i]) lst[i][a[i]] = i;
            else lst[i][j] = ((i == 0) ? -1 : lst[i - 1][j]);
        }
    }
    vector<Point> v; v.reserve(n * 2);
    for (int i = 0, x, y; i < n; i++) {
        cin >> x >> y;
        v.push_back({x, y});
    }
    for (int i = 0; i < n; i++) v.push_back(v[i]);
    vector<vector<int>> f(2 * n + 5, vector<int>(2 * n + 5, -1));
    int ans = 0;
    for (int len = 1; len <= n; len++) {
        for (int l = 0; l + len - 1 < 2 * n; l++) {
            int r = l + len - 1;
            if (a[l] != a[r]) continue;
            if (len <= 2) {
                f[l][r] = 0;
                continue;
            }
            for (int k = l + 1; k < r; k++) {
                int pl = k;
                int pr = lst[r][a[pl]];
                if (pr < pl || f[pl][pr] == -1) continue;
                cmax(f[l][r], f[pl][pr] + Area(v[l], v[r], v[pr]) + Area(v[l], v[pr], v[pl]));
                cmax(ans, f[l][r]);
            }
        }
    }
    cout << ans << endl;
}

signed main() {
    ios::sync_with_stdio(0);
    cin.tie(0), cout.tie(0);
    int T = 1;
    cin >> T;
    while (T--) Solve();
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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

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

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:

3938
1068
877
516
2668
3559
1165
3637
560
925
3502
708
3824
1746
2970
1987
613
2221
1245
4762
1900
1646
564
273
3203
6572
1070
3378
1024
799
142
3104
1883
9445
2128
395
1741
2657
1276
480
2107
5119
5458
2446
4031
2249
4378
5192
2226
1473
3016
1770
2160
1655
3367
2088
1459
2663
2617
2447
4239
215
578...

result:

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