QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#725192 | #9417. Palindromic Polygon | Loging | WA | 0ms | 7808kb | C++14 | 3.5kb | 2024-11-08 16:37:34 | 2024-11-08 16:37:35 |
Judging History
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 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]);
int p=(L-1+n)%n;
while(p!=R){
int Lx=p,Rx=Pre[p][val[p]];
if(!In(L,R,Lx)&&!In(L,R,Rx)&&!In(Lx,L,Rx)){
// 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));
}
p=(p-1+n)%n;
}
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)){
res=max(res,cross(A[Lx],A[L])+cross(A[R],A[Rx])+dfs(Lx,Rx));
}
// Lx=Pre[L][i];Rx=Pre[Lx][i];
// if(!In(L,R,Lx)&&!In(L,R,Rx)){
// res=max(res,cross(A[Lx],A[L])+cross(A[R],A[Rx])+dfs(Lx,Rx));
// }
//
// Rx=Nxt[R][i];Lx=Nxt[Rx][i];
// if(!In(L,R,Lx)&&!In(L,R,Rx)){
// res=max(res,cross(A[Lx],A[L])+cross(A[R],A[Rx])+dfs(Lx,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: 5784kb
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: 7704kb
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: 7808kb
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 765 142 3038 1615 9445 2122 320 1741 2561 1145 480 2094 5119 5458 2446 3929 2249 4378 4927 2341 1473 3152 1574 1990 1609 3367 2298 1459 2663 2617 2298 4048 215 546...
result:
wrong answer 12th numbers differ - expected: '696', found: '512'