QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#621286 | #9417. Palindromic Polygon | Zhou_JK | WA | 1ms | 5784kb | C++14 | 2.2kb | 2024-10-08 12:03:41 | 2024-10-08 12:03:45 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
constexpr int N=505;
int n,m;
int a[N];
int va[N];
int nxt[N][N],lst[N][N];
struct Point
{
int x,y;
friend long long cross(const Point &a,const Point &b)
{
return (long long)a.x*b.y-(long long)a.y*b.x;
}
}p[N];
long long dp[N][N];
long long dfs(int l,int r)
{
if(dp[l][r]!=-1) return dp[l][r];
if(l==r) return dp[l][r]=0;
// cerr<<"now"<<"dp"<<l<<" "<<r<<"\n";
assert(a[l]==a[r]);
long long res=cross(p[l],p[r]);
for(int i=(l+1)%n;i!=r;i=(i+1)%n)
{
int j=lst[(r-1+n)%n][a[i]];
// cerr<<"now"<<i<<" "<<j<<"\n";
res=max(res,dfs(i,j)+cross(p[l],p[i])+cross(p[j],p[r]));
}
// for(int k=0;k<m;k++)
// {
// int i=nxt[(l+1)%n][k],j=lst[(r-1+n)%n][k];
// if(i==-1||j==-1) continue;
// if(l<=r&&!((i>l&&i<r)&&(j>l&&j<r))) continue;
// if(l>=r&&!((i<r||i>l)&&(j<r||j>l))) continue;
// // cerr<<"next from"<<l<<" "<<r<<" to "<<i<<" "<<j<<"\n";
// }
// cerr<<"dp"<<l<<" "<<r<<" "<<res<<"\n";
return dp[l][r]=res;
}
void solve()
{
cin>>n;
for(int i=0;i<n;i++)
cin>>a[i];
m=0;
for(int i=0;i<n;i++)
va[m++]=a[i];
sort(va,va+m);
m=unique(va,va+m)-va;
for(int i=0;i<n;i++)
a[i]=lower_bound(va,va+m,a[i])-va;
for(int i=0;i<n;i++)
{
int x,y;
cin>>x>>y;
p[i]={x,y};
}
for(int i=0;i<n;i++)
{
for(int j=0;j<m;j++)
nxt[i][j]=lst[i][j]=-1;
for(int j=0;j<n;j++)
if(nxt[i][a[(i+j)%n]]==-1) nxt[i][a[(i+j)%n]]=(i+j)%n;
for(int j=0;j<n;j++)
if(lst[i][a[(i-j+n)%n]]==-1) lst[i][a[(i-j+n)%n]]=(i-j+n)%n;
}
// cout<<"done\n";
for(int i=0;i<n;i++)
for(int j=0;j<n;j++)
dp[i][j]=-1;
long long ans=0;
for(int i=0;i<n;i++)
for(int j=0;j<n;j++)
if(a[i]==a[j]) ans=max(ans,dfs(i,j)+cross(p[j],p[i]));
cout<<ans<<"\n";
return;
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr),cout.tie(nullptr);
int T;
cin>>T;
while(T--)
solve();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 5760kb
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: 1ms
memory: 5644kb
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: 5784kb
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 696 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 2299 1473 2944 1574 1990 1609 3367 2088 1459 2663 2617 2298 4048 215 546...
result:
wrong answer 49th numbers differ - expected: '2356', found: '2299'