QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#187426 | #3858. Systematic salesman | doll_sister# | RE | 16ms | 101460kb | C++14 | 3.0kb | 2023-09-24 17:12:38 | 2023-09-24 17:12:39 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 1005;
int n,X[1005],Y[1005];
bool cmp1(int a,int b){
return X[a]<X[b];
}
bool cmp2(int a,int b){
return Y[a]<Y[b];
}
vector<int> A[N],indep[N];
vector<double> dp[N][N<<2];
int mxdep,bel[N][N];
void init(int k,int dep,vector<int> id,int type) {
//cout<<k<<' '<<dep<<'\n';
A[k]=id;
indep[dep].push_back(k);
mxdep=max(mxdep,dep);
for(int i:id)bel[dep][i]=k;
if(id.size()==1)return ;
vector<int> S,T;
S = id;
if(type==0)
sort(S.begin(),S.end(),cmp1);
else
sort(S.begin(),S.end(),cmp2);
int K = id.size() - id.size()/2;
for(int i=1;i<=K;i++){
T.push_back(S.back());
S.pop_back();
}
sort(S.begin(),S.end());
sort(T.begin(),T.end());
init(k<<1,dep+1,S,type^1);
init(k<<1|1,dep+1,T,type^1);
}
/*void Dp(int k,int id){
if(A[id].size()==1){
dp[k][id].push_back(hypot(X[k]-X[A[id][0]],Y[k]-Y[A[id][0]]));
return ;
}
Dp(k,id<<1);
Dp(k,id<<1|1);
for(int i=0;i<A[id<<1].size();i++){
for(int j=0;j<A[id<<1|1].size();j++){
dp[k][j]=min(dp[k])
}
}
}*/
double u[N];
const double eps=1e-9;
void Print(int k,int jj,int l){
if(A[jj].size()==1){
cout<<A[jj][0]<<' ';
return ;
}
int p=A[jj][l];
double rw=dp[k][jj][l];
for(int i=0;i<A[jj<<1].size();i++){
for(int j=0;j<A[jj<<1|1].size();j++){
if(A[jj<<1|1][j]!=p)continue;
double w=dp[k][jj<<1][i]+dp[A[jj<<1][i]][jj<<1|1][j];
if(fabs(w-rw)<eps){
Print(k,jj<<1,i);
Print(A[jj<<1][i],jj<<1|1,j);
return ;
}
}
}
for(int i=0;i<A[jj<<1|1].size();i++){
for(int j=0;j<A[jj<<1].size();j++){
if(A[jj<<1][j]!=p)continue;
double w=dp[k][jj<<1|1][i]+dp[A[jj<<1|1][i]][jj<<1][j];
if(fabs(w-rw)<eps){
Print(k,jj<<1|1,i);
Print(A[jj<<1|1][i],jj<<1,j);
return ;
}
}
}
}
int main(){
scanf("%d",&n);
for(int i=1;i<=n;i++){
cin>>X[i]>>Y[i];
}
vector<int> c;
for(int i=1;i<=n;i++)c.push_back(i);
init(1,1,c,0);
fill(u+1,u+n+1,1e18);
for(int ii=mxdep;ii>=1;ii--){
for(int jj:indep[ii]){
for(int k=1;k<=n;k++){
if(A[jj].size()==1){
dp[k][jj].push_back(hypot(X[k]-X[A[jj][0]],Y[k]-Y[A[jj][0]]));
continue;
}
for(int i=0;i<A[jj<<1].size();i++){
for(int j=0;j<A[jj<<1|1].size();j++){
u[A[jj<<1|1][j]]=min(u[A[jj<<1|1][j]],dp[k][jj<<1][i]+dp[A[jj<<1][i]][jj<<1|1][j]);
}
}
for(int i=0;i<A[jj<<1|1].size();i++){
for(int j=0;j<A[jj<<1].size();j++){
u[A[jj<<1][j]]=min(u[A[jj<<1][j]],dp[k][jj<<1|1][i]+dp[A[jj<<1|1][i]][jj<<1][j]);
}
}
for(int i:A[jj])dp[k][jj].push_back(u[i]),u[i]=1e18;
}
}
}
double ans=1e18;
int mnp=0,mmnp=0;
for(int k=1;k<=n;k++){
for(int l=0;l<n;l++){
if(dp[k][1][l]<ans){
ans=dp[k][1][l];
mnp=k;
mmnp=l;
}
}
}
printf("%.12lf\n",ans);
Print(mnp,1,mmnp);
// for(int i=1;i<=n<<2;i++){
// if(!A[i].size())continue;
// for(auto x:A[i])cout << x << ' ';
// cout << endl;
// }
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 12ms
memory: 99712kb
input:
8 7 3 2 0 4 5 1 4 8 2 9 9 0 8 6 1
output:
26.383325771613 6 1 5 8 2 4 3 7
result:
ok correct!
Test #2:
score: 0
Accepted
time: 8ms
memory: 100032kb
input:
20 4 71 52 7 49 15 59 83 12 9 46 6 74 44 89 50 32 10 82 58 11 33 78 72 27 49 64 75 97 0 38 46 91 54 8 70 18 61 79 92
output:
374.883681117480 1 18 19 13 16 11 5 9 3 6 2 7 15 8 17 10 12 20 4 14
result:
ok correct!
Test #3:
score: 0
Accepted
time: 16ms
memory: 101460kb
input:
100 192 64 839 68 846 688 911 133 110 439 592 226 355 364 418 487 402 466 436 425 509 847 542 78 648 404 954 313 726 906 777 922 596 550 159 172 507 651 720 932 575 805 889 193 246 206 175 326 897 464 108 70 790 2 548 624 867 222 743 269 41 98 348 173 49 915 35 939 404 571 371 625 363 758 317 155 90...
output:
8491.452160233977 31 26 86 1 98 18 93 79 5 45 90 24 23 38 42 57 32 56 85 49 67 7 10 9 41 63 83 62 96 47 39 33 34 48 72 91 60 61 88 11 92 80 99 37 89 36 35 8 82 19 75 28 44 17 71 78 55 97 69 50 58 21 15 20 81 16 74 66 76 87 3 46 54 77 95 68 73 25 52 43 14 84 4 22 29 40 2 27 100 53 12 65 6 30 64 51 13...
result:
ok correct!
Test #4:
score: -100
Runtime Error
input:
500 380 190 314 738 973 705 875 517 593 638 132 681 714 411 400 589 139 353 339 771 832 883 610 170 925 431 351 96 884 683 674 817 5 386 710 99 348 173 996 812 533 453 851 10 877 142 86 361 860 168 489 50 641 766 158 118 989 745 823 559 374 971 605 158 432 307 931 863 719 635 73 341 726 906 536 372 ...