QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#609512#9417. Palindromic PolygonUESTC_OldEastWest#WA 1ms3616kbC++172.6kb2024-10-04 13:18:342024-10-04 13:18:35

Judging History

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

  • [2024-10-04 13:18:35]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3616kb
  • [2024-10-04 13:18:34]
  • 提交

answer

#pragma GCC optimize("Ofast")
#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 < n && 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;
            }
            // cout << l << " & " << r << endl;
            for (int k = l + 1; k < r; k++) {
                int pl = k;
                int pr = lst[r - 1][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]));
                // cout << "\t" << f[l][r] << " " << pl << " " <<  pr << ": " << f[pl][pr] << " " <<  Area(v[l], v[r], v[pr]) << " "<<  Area(v[l], v[pr], v[pl])<<endl;
                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;
}


/*
1
10
3 3 2 4 0 2 3 2 4 1
7 16
0 0
75 31
80 43
80 55
76 61
63 64
45 51
28 37
13 23
*/

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

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

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
806
877
516
2496
3559
1165
3468
560
925
3502
12
3653
1432
2970
1826
202
1682
1083
4671
1825
1646
564
273
3151
6572
1070
3122
438
765
142
3038
1615
9445
2026
320
1741
2561
1145
480
2094
5119
5214
1590
3929
2249
4378
4927
2299
1473
2944
1574
1990
1609
2246
2088
1391
2663
2617
2224
4048
141
246
13...

result:

wrong answer 2nd numbers differ - expected: '1068', found: '806'