QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#187198 | #3858. Systematic salesman | Nax_hueux# | WA | 0ms | 12184kb | C++14 | 4.2kb | 2023-09-24 15:20:05 | 2023-09-24 15:20:06 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
const int N=1100;
const double inf=2e9;
int n,newp[N];
struct point {
double x,y;
int id;
}pos[N];
bool cmpx(point a,point b) {
return a.x<b.x;
}
bool cmpy(point a,point b) {
return a.y<b.y;
}
struct tree {
int l,r,dep,mid;
}t[N<<2];
#define ls(k) ((k)<<1)
#define rs(k) ((k)<<1|1)
inline void build(int k,int l,int r,int d) {
t[k].l=l,t[k].r=r,t[k].dep=d;
// printf("tree:[%d,%d] dep:%d\n",l,r,d);
if(l==r) {
newp[pos[l].id]=l;
return ;
}
if(d&1) sort(pos+l+1,pos+r+1,cmpx);
else sort(pos+l+1,pos+r+1,cmpy);
int mid=(l+r-1)>>1; t[k].mid=mid;
build(ls(k),l,mid,d+1);
build(rs(k),mid+1,r,d+1);
}
int frm[N][N][2],frmz[N][N];
double s[N][N],f[N][N],z[N][N];
double dis(point a,point b) {
return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));
}
#define tll t[ls(ls(k))]
#define tlr t[rs(ls(k))]
#define trl t[ls(rs(k))]
#define trr t[rs(rs(k))]
inline bool cmin(double &x,double y) {
if(x>y) {x=y;return true;}
return false;
}
inline void work(int k) {
if(t[k].r-t[k].l+1==2) {
f[t[k].l][t[k].r]=s[t[k].l][t[k].r];
return ;
} else if(t[k].r-t[k].l+1==3) {
f[t[k].l][t[k].l+1]=s[t[k].l][t[k].l+2]+s[t[k].l+1][t[k].l+2];
f[t[k].l][t[k].l+2]=s[t[k].l][t[k].l+1]+s[t[k].l+1][t[k].l+2];
return ;
}
work(ls(k));
work(rs(k));
int i1,i2,i3;
for(i1=tll.l;i1<=tll.r;i1++) {
for(i2=tlr.l;i2<=tlr.r;i2++) {
for(i3=trl.l;i3<=trl.r;i3++) {
if(cmin(z[i1][i3],f[i1][i2]+s[i2][i3])) frmz[i1][i3]=i2;
}
for(i3=trr.l;i3<=trr.r;i3++) {
if(cmin(z[i1][i3],f[i1][i2]+s[i2][i3])) frmz[i1][i3]=i2;
}
}
for(i2=trl.l;i2<=trl.r;i2++) {
for(i3=trr.l;i3<=trr.r;i3++) {
if(cmin(f[i1][i3],z[i1][i2]+f[i2][i3])) frm[i1][i3][0]=frmz[i1][i3],frm[i1][i3][1]=i2;
}
}
for(i2=trr.l;i2<=trr.r;i2++) {
for(i3=trl.l;i3<=trl.r;i3++) {
if(cmin(f[i1][i3],z[i1][i2]+f[i3][i2])) frm[i1][i3][0]=frmz[i1][i3],frm[i1][i3][1]=i2;
}
}
}
for(i1=tlr.l;i1<=tlr.r;i1++) {
for(i2=tll.l;i2<=tll.r;i2++) {
for(i3=trl.l;i3<=trl.r;i3++) {
if(cmin(z[i1][i3],f[i2][i1]+s[i2][i3])) frmz[i1][i3]=i2;
}
for(i3=trr.l;i3<=trr.r;i3++) {
if(cmin(z[i1][i3],f[i2][i1]+s[i2][i3])) frmz[i1][i3]=i2;
}
}
for(i2=trl.l;i2<=trl.r;i2++) {
for(i3=trr.l;i3<=trr.r;i3++) {
if(cmin(f[i1][i3],z[i1][i2]+f[i2][i3])) frm[i1][i3][0]=frmz[i1][i3],frm[i1][i3][1]=i2;
}
}
for(i2=trr.l;i2<=trr.r;i2++) {
for(i3=trl.l;i3<=trl.r;i3++) {
if(cmin(f[i1][i3],z[i1][i2]+f[i3][i2])) frm[i1][i3][0]=frmz[i1][i3],frm[i1][i3][1]=i2;
}
}
}
}
inline void print(int k,int S,int T) {
if(t[k].r-t[k].l+1==2) {
printf("%d %d ",pos[S].id,pos[T].id);
return ;
} else if(t[k].r-t[k].l+1==3) {
printf("%d %d %d ",pos[S].id,pos[t[k].l].id+pos[t[k].l+1].id+pos[t[k].l+2].id-pos[S].id-pos[T].id,pos[T].id);
return ;
}
if(S<=t[k].mid) {
print(ls(k),S,frm[min(S,T)][max(S,T)][0]);
print(rs(k),frm[min(S,T)][max(S,T)][1],T);
} else {
print(rs(k),S,frm[min(S,T)][max(S,T)][1]);
print(ls(k),frm[min(S,T)][max(S,T)][0],T);
}
}
int main() {
scanf("%d",&n);
for(int i=1;i<=n;i++)
scanf("%lf%lf",&pos[i].x,&pos[i].y),pos[i].id=i;
if(n==1) {
puts("0\n1");
return 0;
}
build(1,1,n,1);
// for(int i=1;i<=n;i++) printf("%d ",pos[i].id);puts("");
for(int i=1;i<=n;i++)
for(int j=i+1;j<=n;j++) {
s[i][j]=dis(pos[i],pos[j]);
f[i][j]=z[i][j]=inf;
}
work(1);
double mx=inf;
int mxf1,mxf2;
for(int i=t[2].l;i<=t[2].r;i++)
for(int j=t[3].l;j<=t[3].r;j++) {
if(cmin(mx,f[i][j])) mxf1=i,mxf2=j;
}
printf("%lf\n",mx);
print(1,mxf1,mxf2);
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 12184kb
input:
8 7 3 2 0 4 5 1 4 8 2 9 9 0 8 6 1
output:
31.461986 7 4 2 1 3 8 5 6
result:
wrong answer The first line of your output is 31.461986, but the length of jury's solution is 26.383326