QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#187527#3858. Systematic salesmandfsaab#WA 1ms6148kbC++142.4kb2023-09-24 17:56:312023-09-24 17:56:31

Judging History

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

  • [2023-09-24 17:56:31]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:6148kb
  • [2023-09-24 17:56:31]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
#define M 4005
#define N 1005
#define ckmi(a,b) ((a>b)&&(a=b))
struct hh{
	int x[2],id;
}sk[M];
int n,cnt=1,flag=1,son[M][2],sz[M];
vector<hh>tr[M];
bool cmp(hh a,hh b){
	return a.x[flag]<b.x[flag];
}
void build(int rt){
	sz[rt]=tr[rt].size();
	if(tr[rt].size()==1)return;
	flag^=1;
	sort(tr[rt].begin(),tr[rt].end(),cmp);
	for(int i=1;i<=sz[rt];++i){
		if(i*2<=sz[rt])tr[cnt+1].push_back(tr[rt][i-1]);
		else tr[cnt+2].push_back(tr[rt][i-1]);
	}
	son[rt][0]=++cnt;son[rt][1]=++cnt;
	build(son[rt][0]);
	build(son[rt][1]);
	flag^=1;
}
int to[M];
vector<vector<double>>dp[M];
double ls[N][N],dis[N][N],mi[M][2];
void dfs(int rt){
	dp[rt].resize(sz[rt]);
	for(int i=0;i<sz[rt];++i)dp[rt][i].resize(sz[rt]);
	if(sz[rt]==1){
		dp[rt][0][0]=0;	
		return;
	}
	dfs(son[rt][0]);dfs(son[rt][1]);
	for(int i=0;i<sz[rt];++i)
		for(int j=0;j<sz[rt];++j)dp[rt][i][j]=1e18;
	mi[rt][0]=mi[rt][1]=1e18;
	for(int now=0;now<2;++now){
		int st=son[rt][now],ed=son[rt][now^1];
		for(int j=0;j<sz[st];++j)
			for(int k=0;k<sz[ed];++k)ls[j][k]=1e18;
			
		for(int p1=0;p1<sz[st];++p1)
			for(int p2=0;p2<sz[st];++p2){
				int now1=tr[st][p2].id;
				for(int p3=0;p3<sz[ed];++p3)
					ckmi(ls[p1][p3],dp[st][p1][p2]+dis[now1][tr[ed][p3].id]);
			}
		for(int p1=0;p1<sz[st];++p1)
			for(int p2=0;p2<sz[ed];++p2)
				for(int p3=0;p3<sz[ed];++p3){
					if(!now)ckmi(dp[rt][p1][p3+sz[st]],ls[p1][p2]+dp[ed][p2][p3]);
					else ckmi(dp[rt][p1+sz[ed]][p3],ls[p1][p2]+dp[ed][p2][p3]);
				}
		for(int p1=0;p1<sz[st];++p1)
			for(int p2=0;p2<sz[ed];++p2){
				if(!now)ckmi(mi[rt][now],dp[rt][p1][p2+sz[st]]);
				else ckmi(mi[rt][now],dp[rt][p1+sz[ed]][p2]);
			}
	}
}
int ans[M],fuck;
void Dfs(int rt){
	if(sz[rt]==1){
		ans[++fuck]=tr[rt][0].id+1;
		return;
	}
	if(mi[rt][0]<mi[rt][1])Dfs(son[rt][0]),Dfs(son[rt][1]);
	else Dfs(son[rt][1]),Dfs(son[rt][0]);
}
int main(){
	scanf("%d",&n);
	for(int i=1,x,y;i<=n;++i){
		scanf("%d%d",&x,&y);
		hh s;
		s.x[0]=x;s.x[1]=y;s.id=i-1;
		tr[1].push_back(s);
	}
	for(int i=0;i<n;++i)
		for(int j=0;j<n;++j){
			int x1=tr[1][i].x[0];
			int y1=tr[1][i].x[1];
			int x2=tr[1][j].x[0];
			int y2=tr[1][j].x[1];
			dis[i][j]=sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));
		}
	build(1);
	dfs(1);
	printf("%.10lf\n",min(mi[1][0],mi[1][1]));
	Dfs(1);
	for(int i=1;i<=n;++i)printf("%d ",ans[i]);
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 1ms
memory: 6148kb

input:

8
7 3
2 0
4 5
1 4
8 2
9 9
0 8
6 1

output:

26.7323561010
6 1 5 8 3 7 2 4 

result:

wrong answer The first line of your output is 26.732356, but the length of jury's solution is 26.383326