Submission #311933

# Submission time Handle Problem Language Result Execution time Memory
311933 2020-10-12T03:27:53 Z decoqwq Vrtić (COCI18_vrtic) C++14
0 / 160
18 ms 368 KB
#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())
			{
			}
			else
			{
				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

vrtic.cpp: In function 'int main()':
vrtic.cpp:50:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   50 |   scanf("%d",&to[i]);
      |   ~~~~~^~~~~~~~~~~~~
vrtic.cpp:54:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   54 |   scanf("%d",&st[i]);
      |   ~~~~~^~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 10 ms 256 KB the dissatisfaction value doesn't match with your answer
# Verdict Execution time Memory Grader output
1 Incorrect 16 ms 256 KB the dissatisfaction value doesn't match with your answer
# Verdict Execution time Memory Grader output
1 Incorrect 6 ms 256 KB the dissatisfaction value doesn't match with your answer
# Verdict Execution time Memory Grader output
1 Incorrect 10 ms 256 KB the dissatisfaction value doesn't match with your answer
# Verdict Execution time Memory Grader output
1 Incorrect 6 ms 256 KB the dissatisfaction value doesn't match with your answer
# Verdict Execution time Memory Grader output
1 Incorrect 15 ms 256 KB the dissatisfaction value doesn't match with your answer
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 15 ms 256 KB the dissatisfaction value doesn't match with your answer
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 14 ms 256 KB the dissatisfaction value doesn't match with your answer
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 17 ms 368 KB the dissatisfaction value doesn't match with your answer
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 18 ms 360 KB the dissatisfaction value doesn't match with your answer
2 Halted 0 ms 0 KB -