QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#724947#9417. Palindromic PolygonLogingWA 1ms7712kbC++143.2kb2024-11-08 15:39:472024-11-08 15:39:47

Judging History

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

  • [2024-11-08 15:39:47]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:7712kb
  • [2024-11-08 15:39:47]
  • 提交

answer

#include<cstdio>
#include<algorithm>
#define M 1005
#define i64 __int128
using namespace std;
struct Point{
    long long x,y;
}A[M];
i64 cross(Point a,Point b){
    return i64(a.x)*b.y-i64(a.y)*b.x;
}
int val[M];
i64 sum[M];
int n;
// i64 Get_val(int L,int R){
//     if(L==R)return 0;
//     // printf("<%d %d>\n",L,R);
//     // puts("B");
//     i64 res=0;
//     if(L<=R){
//         if(L)res=sum[R-1]-sum[L-1]+cross(A[R],A[L]);
//         else res=sum[R-1]+cross(A[R],A[L]);
//     }else{
//         if(R==0)res=sum[n-1]-sum[L-1]+cross(A[R],A[L]);
//         else res=sum[n-1]-sum[L-1]+cross(A[R],A[L])+sum[R-1];
//     }
//     // printf("[%d %d]%lld\n",L,R,res);
//     // puts("E");
//     return res;
// }
int lst[M],Nxt[M][M],Pre[M][M];
i64 dp[M][M];
bool check(int L1,int R1,int L2,int R2){
    if(L1>R1)R1+=n;
    if(L2>R2)R2+=n;
    return (L1<=L2%n&&L2%n<=R1)||(L1<=R2%n&&R2%n<=R1)||(L2<=L1%n&&L1%n<=R2)||(L2<=R1%n&&R1%n<=R2);
}
bool In(int Lx,int Rx,int d){
    if(Lx<=Rx)return Lx<=d&&d<=Rx;
    return d>=Lx||d<=Rx;
}
bool mark[M][M];
int B[M],sz;
i64 dfs(int L,int R){
    // printf("[%d %d]\n",L,R);
    if(L==R)return 0;
    if(mark[L][R])return dp[L][R];
    mark[L][R]=true;
    i64 res=cross(A[R],A[L]);
    for(int i=0;i<sz;i++){
        int Lx=Pre[L][i],Rx=Nxt[R][i];
        // if(check(Lx,L,R,Rx))continue;
        if(In(L,R,Lx)||In(L,R,Rx))continue;
        // printf("[%d %d]-->[%d %d]\n",L,R,Lx,Rx);
        res=max(res,cross(A[Lx],A[L])+cross(A[R],A[Rx])+dfs(Lx,Rx));
        res=max(res,cross(A[Lx],A[L])+cross(A[R],A[Lx])+dfs(Lx,Lx));
        res=max(res,cross(A[Rx],A[L])+cross(A[R],A[Rx])+dfs(Rx,Rx));
    }
    // printf("dp[%d][%d]=%lld\n",L,R,dp[L][R]);
    return dp[L][R]=res;
}
int main(){
    int T;
    scanf("%d",&T);
    while(T--){
        scanf("%d",&n);
        for(int i=0;i<n;i++){
            scanf("%d",&val[i]);
            B[i]=val[i];
        }
        for(int i=0;i<n;i++){
            scanf("%lld%lld",&A[i].x,&A[i].y);
        }
        for(int i=1;i<=n;i++)lst[i]=0;
        for(int i=0;i<n;i++)for(int j=0;j<n;j++)mark[i][j]=false;
        // printf("res=%lld\n",res);
        sort(B,B+n);
        sz=unique(B,B+n)-B;
        for(int i=0;i<n;i++)val[i]=lower_bound(B,B+sz,val[i])-B;
        for(int i=0;i<2*n;i++){
            for(int j=0;j<sz;j++){
                Pre[i%n][j]=lst[j];
            }
            lst[val[i%n]]=i%n;
        }
        for(int i=2*n-1;i>=0;i--){
            for(int j=0;j<sz;j++){
                Nxt[i%n][j]=lst[j];
            }
            lst[val[i%n]]=i%n;
        }
        // for(int i=0;i<n;i++){
        //     i64 val=cross(A[i],A[(i+1)%n]);
        //     if(i)sum[i]=sum[i-1]+val;
        //     else sum[i]=val;
        // }
        // puts("Initok");
        i64 res=0;
        for(int i=0;i<n;i++){
            // printf("i=%d\n",i);
            int Lx=i,Rx=Nxt[i][val[i]];
            if(Lx==Rx)continue;
            // printf("@i=%d\n",i);
            // if(Lx==Rx)continue;
            res=max(res,dfs(Lx,Rx)+cross(A[Lx],A[Rx]));
            // printf("@@i=%d\n",i);
        }
        long long ans=res;
        printf("%lld\n",ans);

        // printf("%lf\n",res/2.0);
    }
    return 0;
}

详细

Test #1:

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

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

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

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
2668
3559
1165
3468
560
925
3502
512
3824
1746
2970
1826
613
2221
1130
4677
1900
1646
564
273
3203
6572
1070
3330
1024
575
142
3038
1615
9445
2122
320
1741
2561
1145
480
1927
5119
5458
2446
3929
2249
4378
4927
2299
1473
2944
1574
1856
1609
3367
2088
1459
2663
2617
2298
4048
215
546...

result:

wrong answer 12th numbers differ - expected: '696', found: '512'