QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#187479 | #3858. Systematic salesman | zhylj# | WA | 2ms | 12012kb | C++14 | 2.4kb | 2023-09-24 17:42:20 | 2023-09-24 17:42:20 |
Judging History
answer
#include<bits/stdc++.h>
#define int ll
#define mp make_pair
#define qr read()
#define nc getchar
#define in(x) x=read()
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
inline int read()
{
char ch=' ';
int f=1,x=0;
for(;!isdigit(ch);ch=nc())if(ch=='-')f*=-1;
for(;isdigit(ch);ch=nc())x=x*10+ch-'0';
return f*x;
}
bool blank(char ch){return ch==' '||ch=='\n'||ch=='\t';}
struct p
{
int x,y;
}e[1000010];
vector<int>v;
bool cmp1(int e1,int e2){return e[e1].x>e[e2].x;}
bool cmp2(int e1,int e2){return e[e1].y<e[e2].y;}
int pos[1000010],id[1000010],siz[1000010];
void build(vector<int>v,int x,int f)
{
if(v.size()==1)
{
id[x]=v[0];
pos[v[0]]=x;
siz[x]=1;
return;
}
if(!f)sort(v.begin(),v.end(),cmp1);
else sort(v.begin(),v.end(),cmp2);
vector<int>v1,v2;
int n=v.size();
for(int i=0;i<n/2;i++)v1.push_back(v[i]);
for(int i=n/2;i<n;i++)v2.push_back(v[i]);
build(v1,x<<1,f^1);
build(v2,x<<1|1,f^1);
siz[x]=siz[x<<1]+siz[x<<1|1]+1;
}
vector<int>lis,lis2;
void dfs(int x)
{
if(id[x])
{
v.push_back(id[x]);
return;
}
if(siz[x<<1])dfs(x<<1);
if(siz[x<<1|1])dfs(x<<1|1);
}
int pp,vis[1000010];
long double calc(int x,int y)
{
return sqrtl((e[x].x-e[y].x)*(e[x].x-e[y].x)+(e[x].y-e[y].y)*(e[x].y-e[y].y));
}
bool cmp3(int a,int b)
{
return calc(pp,a)<calc(pp,b);
}
signed main()
{
int n=qr;
for(int i=1;i<=n;i++)
{
in(e[i].x),in(e[i].y);
}
int f=0;
for(int i=1;i<=n;i++)v.push_back(i);
build(v,1,0);
long double mn=1e16;
for(int i=1;i<=n;i++)
{
// cout<<"--------\n";
int nw=i;
long double now=0;
lis.clear();
while(1)
{
// cout<<nw<<' ';
lis.push_back(nw);
int p=pos[nw];
vis[p]=1;
while((vis[p^1]||!siz[p^1])&&p)p>>=1,vis[p]=1;
if(!p)break;
v.clear();
dfs(p^1);
pp=nw;
sort(v.begin(),v.end(),cmp3);
now+=calc(nw,v[0]);
nw=v[0];
}
for(int j=1;j<=4*n;j++)vis[j]=0;
// cout<<i<<":\n";
// for(auto i:lis)cout<<i<<' ';cout<<'\n';
// cout<<'\n';
if(now<mn)lis2=lis,mn=now;
}
printf("%.6Lf\n",mn);
for(auto i:lis2)cout<<i<<' ';
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 2ms
memory: 11904kb
input:
8 7 3 2 0 4 5 1 4 8 2 9 9 0 8 6 1
output:
26.383326 7 3 4 2 8 5 1 6
result:
ok correct!
Test #2:
score: -100
Wrong Answer
time: 2ms
memory: 12012kb
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:
433.101446 1 18 19 13 16 11 9 5 6 3 2 7 8 17 15 10 20 12 14 4
result:
wrong answer The first line of your output is 433.101446, but the length of jury's solution is 374.883681