# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
311938 | decoqwq | Vrtić (COCI18_vrtic) | C++14 | 18 ms | 372 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
int to[160],st[160],n,a[160],ans;
int gans()
{
int qwq=0;
for(int i=1;i<=n;i++)
{
qwq=max(qwq,abs(st[a[i]]-st[a[to[i]]]));
}
return qwq;
}
void SA()
{
double Temp=3000;
ans=gans();
while(Temp>1e-4)
{
int x=rand()%n+1,y=rand()%n+1;
while(x==y)
{
x=rand()%n+1,y=rand()%n+1;
}
swap(a[x],a[y]);
int qwq=gans();
if(qwq<ans)
{
ans=qwq;
}
else
{
if(exp((double)(ans-qwq)/Temp)*32767.0<=rand())
{
swap(a[x],a[y]);
}
}
Temp*=0.96;
}
}
int main()
{
srand(19260817);
cin>>n;
ans=0x3f3f3f3f;
for(int i=1;i<=n;i++)
{
scanf("%d",&to[i]);
}
for(int i=1;i<=n;i++)
{
scanf("%d",&st[i]);
a[i]=i;
}
random_shuffle(a+1,a+n+1);
for(int i=1;i<=100;i++)
{
SA();
}
cout<<ans<<"\n";
for(int i=1;i<=n;i++)
{
cout<<st[a[i]]<<" ";
}
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |