QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#610073#9417. Palindromic PolygonUESTC_PenaltyAutomaton#WA 1ms5928kbC++144.2kb2024-10-04 14:52:032024-10-04 14:52:04

Judging History

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

  • [2024-10-04 14:52:04]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:5928kb
  • [2024-10-04 14:52:03]
  • 提交

answer

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<map>
#include<vector>
#include <valarray>
#include <cmath>
#include <numeric>
#include <random>
#include <unordered_map>
#include <queue>

using namespace std;

#define ll long long
#define pr pair<int, int>

const int maxN = 5e2+10, mod = 998244353, inf = 1e9+10;
int n;
ll dp1[maxN][maxN], dp2[maxN][maxN];
unordered_map<int, int> last[maxN], fir[maxN];

struct point{
    ll x, y;
    int f;
}p[maxN];

struct vect{
    ll x, y;
};

vect operator-(point x, point y){
    return vect{x.x-y.x, x.y-y.y};
}

ll operator^(vect x, vect y){
    return abs(x.x*y.y-x.y*y.x);
}

ll power(ll x, ll y){
    ll an = 1;
    while (y){
        if (y & 1) an = an*x % mod;
        x = x*x % mod;
        y >>= 1;
    }
    return an;
}

ll cal(point& x, point& y, point& z, point& r){
    return ((x-y)^(y-z))+((x-r)^(r-z));
}

ll cal(point& x, point& y, point& z){
    return (x-y)^(y-z);
}

ll inv(ll x){
    return power(x, mod-2);
}

void solve() {
    cin >> n;
    last[0].clear();
    for (int i = 1; i <= n; ++i){
        cin >> p[i].f;
        last[i] = last[i-1];
        last[i][p[i].f] = i;
    }
    fir[n+1].clear();
    for (int i = n; i >= 1; --i) {
        fir[i] = fir[i+1];
        fir[i][p[i].f] = i;
    }
    for (int i = 1; i <= n; ++i) {
        for (int j = 1; j <= n; ++j) {
            dp2[i][j] = dp1[i][j] = 0;
        }
    }
    for (int i = 1; i <= n; ++i) cin >> p[i].x >> p[i].y;

    for (int i = 3; i <= n; ++i) {
        for (int j = 1; j <= n-i; ++j) {
            if (p[j].f == p[j+i].f){
                int mx = 0;
                for (int k = j+1; k <= j+i-1; ++k) {
                    if (last[j+i-1][p[k].f] >= max(mx, k+1)){
                        mx = last[j+i-1][p[k].f];
                        dp1[j][j+i] = max(dp1[k][mx]+ cal(p[j], p[j+i], p[mx], p[k]), dp1[j][j+i]);
                    }
                }
            }
        }
    }

    for (int i = n-3; i >= 1; --i) {
        for (int j = 1; j <= n-i; ++j) {
            if (p[j].f == p[j+i].f){
                int mx = 0, x;
                for (int k = j-1; k >= 1; --k) {
                    x = fir[j+i+1][p[k].f];
                    if (x > j+i){
                        dp2[j][j+i] = max(dp2[j][j+i], dp2[k][x]+ cal(p[k], p[x], p[j+i], p[j]));
                    }else{
                        x = fir[1][p[k].f];
                        if (x < k) dp2[j][j+i] = max(dp2[j][j+i], dp2[k][x]+cal(p[k], p[x], p[j+i], p[j]));
                    }
                }
                for (int k = n; k >= i+j+1; --k) {
                    x = fir[j+i+1][p[k].f];
                    if (x > j+i && x < k) dp2[j][j+i] = max(dp2[j][j+i], dp2[k][x]+ cal(p[k], p[x], p[j+i], p[j]));
                }
            }
        }
    }

    ll an = 0;
    int mx = 0;
    ll x;
//    for (int i = 1; i <= n; ++i) {
//        for (int j = mx; j <= n; ++j) {
//            if (p[i].f != p[j].f) continue;
//            an = max(an, dp1[i][j]);
//            for (int k = 1; k < i; ++k){
//                x = dp1[i][j]+ cal(p[i], p[j], p[k]);
//                if (an < x) mx = k, an = x;
//            }
//            for (int k = j+1; k <= n; ++k) {
//                x = dp1[i][j]+ cal(p[i], p[j], p[k]);
//                if (an < x) mx = k, an = x;
//            }
//        }
//    }
    for (int i = 1; i <= n; ++i) {
        for (int j = i+1; j <= n; ++j) {
            if (p[i].f != p[j].f) continue;
            an = max(an, dp1[i][j]);
            for (int k = 1; k < i; ++k) an = max(an, dp1[i][j]+ cal(p[k], p[i], p[j]));
            for (int k = j+1; k <= n; ++k) an = max(an, dp1[i][j]+ cal(p[k], p[i], p[j]));
        }
    }
    for (int i = 1; i <= n; ++i) {
        for (int j = i+1; j <= n; ++j) {
            if (p[i].f != p[j].f) continue;
            an = max(an, dp2[i][j]);
            for (int k = i+1; k < j; ++k) {
                an = max(an, dp2[i][j]+cal(p[i], p[j], p[k]));
            }
        }
    }
    cout << an << "\n";
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie();
    int t;
    cin >> t;
    while (t--) solve();
    return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 1ms
memory: 5928kb

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

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: 0ms
memory: 5712kb

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
877
516
2529
3559
1165
3468
560
925
3502
696
3653
1746
2970
1826
613
2221
1130
4677
1900
1646
564
273
3151
6572
1070
3330
1024
765
142
3038
1615
9445
2026
320
1741
2561
1145
480
2094
5119
5458
2446
3929
2249
4378
4927
2356
1473
3152
1574
1856
1609
3367
2298
1459
2663
2617
2298
4048
215
546...

result:

wrong answer 5th numbers differ - expected: '2668', found: '2529'