Submission #311938

#TimeUsernameProblemLanguageResultExecution timeMemory
311938decoqwqVrtić (COCI18_vrtic)C++14
0 / 160
18 ms372 KiB
#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)

vrtic.cpp: In function 'int main()':
vrtic.cpp:47:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   47 |   scanf("%d",&to[i]);
      |   ~~~~~^~~~~~~~~~~~~
vrtic.cpp:51:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   51 |   scanf("%d",&st[i]);
      |   ~~~~~^~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...