QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#610323#9417. Palindromic PolygonUESTC_NLNSWA 2ms9908kbC++142.0kb2024-10-04 15:35:582024-10-04 15:36:02

Judging History

This is the latest submission verdict.

  • [2024-10-04 15:36:02]
  • Judged
  • Verdict: WA
  • Time: 2ms
  • Memory: 9908kb
  • [2024-10-04 15:35:58]
  • Submitted

answer

#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int N=1005,IINF=0x3f3f3f3f;
const ll INF=0x3f3f3f3f3f3f3f3f;
struct point{
	int x,y;
	ll operator ^ (const point &t) const{
		return 1ll*x*t.y-1ll*y*t.x;
	}
}p[N];
int T,n,cnt,f[N],L[N][N],R[N][N],P[N];
int mx,my,px,py,X,Y;
ll F[N][N];
ll ans;
bool vis[N][N];
unordered_map<int,int> mp; 
void clear(int sl,int sr)
{
	for(int i=sl;i<=sr;i++) F[i][i]=0;
	for(int i=sl;i<=sr;i++) for(int j=i+1;j<=sr;j++) F[i][j]=-INF;
	return;
}
void Dfs(int l,int r)
{
	if(F[l][r]!=-INF) return;
	if(l==r) return;
	int lst=0;F[l][r]=p[l]^p[r];
	for(int i=l+1;i<r;i++)
	{
//		if(L[r][f[i]]<=lst) continue;
		lst=L[r][f[i]];
		Dfs(i,lst);
		F[l][r]=max(F[l][r],F[i][lst]+(p[l]^p[i])+(p[lst]^p[r]));
	}
	ans=max(ans,F[l][r]+(p[r]^p[l]));
	return;
}
int g(int x)
{
	if(mp.find(x)==mp.end()) mp[x]=++cnt;
	return mp[x];
}
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);
	cin>>T;
	while(T--)
	{
		cin>>n;cnt=0;ans=-INF;mx=my=-IINF,px=py=IINF;
		for(int i=1;i<=n;i++) cin>>f[i],f[i]=g(f[i]),f[n+i]=f[i];
		for(int i=1;i<=n;i++)
		{
			cin>>p[i].x>>p[i].y,p[n+i]=p[i];
			mx=max(mx,p[i].x);
			my=max(my,p[i].y);
			px=min(px,p[i].x);
			py=min(py,p[i].y);			
		}
		X=(mx+px)/2;
		Y=(my+py)/2;
		for(int i=1;i<=n;i++) p[i].x-=X,p[i].y-=Y;
		for(int i=1;i<=cnt;i++) P[i]=0;
		for(int i=1;i<=n*2;i++)
		{
			for(int j=1;j<=cnt;j++) L[i][j]=P[j];
			P[f[i]]=i;
		}
		for(int i=1;i<=cnt;i++) P[i]=n*2+1;
		for(int i=n*2;i>=1;i--)
		{
			for(int j=1;j<=cnt;j++) R[i][j]=P[j];
			P[f[i]]=i;
		}
		clear(1,n*2);
		for(int i=1;i<=n;i++)
		{
			for(int j=i;j<n+i;j++)
			{
				if(f[i]==f[j]) Dfs(i,j);
			}
		}
		if(ans==-INF) cout<<"0\n";
		else cout<<ans<<"\n";
		mp.clear();
	}
	return 0;
}
/*
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
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
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
*/

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 2ms
memory: 9760kb

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

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: 2ms
memory: 9908kb

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:

16001
3076
3669
3100
16153
24050
13425
22048
4006
2586
20811
2668
25793
21338
13513
10777
8319
10940
8925
22663
3771
10624
564
4527
10658
19728
10340
10420
3923
7362
127
14070
12714
5354
18976
5214
12726
14301
13639
9180
13542
23120
5761
13600
12872
17094
35644
13306
9842
4793
9499
1548
29287
3390
1...

result:

wrong answer 1st numbers differ - expected: '3857', found: '16001'