# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1029338 |
2024-07-20T17:12:55 Z |
Gabriel |
Vrtić (COCI18_vrtic) |
C++17 |
|
6 ms |
604 KB |
#include "bits/stdc++.h"
using namespace std;
vector<int> Grafo, Dulces;
vector<bool> Visitados;
int n;
mt19937 Aleatorio(2);
int Costo(vector<int> Asignado){
int Retorno = 0;
for(int i = 0; i < n; i++){
int Dulce_1 = Dulces[Asignado[i]];
int Dulce_2 = Dulces[Asignado[Grafo[i]]];
int Disconformidad = abs(Dulce_1 - Dulce_2);
Retorno = max(Retorno, Disconformidad);
}
return Retorno;
}
int main(){
//ios_base::sync_with_stdio(0);
//cin.tie(0);
cin>>n;
Grafo.assign(n, 0);
Dulces.assign(n, 0);
Visitados.assign(n, 0);
for(int i = 0; i < n; i++) cin>>Grafo[i];
for(int i = 0; i < n; i++){
cin>>Dulces[i];
Grafo[i]--;
}
double Temperatura = 1000;
double Enfriador = 0.999;
vector<int> Asignar(n);
for(int i = 0; i < n; i++) Asignar[i] = i;
uniform_int_distribution<int> Entero(0, n - 1);
uniform_real_distribution<double> Decimal(0, 1);
int Costo_anterior = Costo(Asignar);
while(Temperatura > 0.000001){
int _1 = Entero(Aleatorio);
int _2 = Entero(Aleatorio);
vector<int> Copia = Asignar;
swap(Copia[_1], Copia[_2]);
int Nuevo = Costo(Copia);
if(Nuevo < Costo_anterior){
Costo_anterior = Nuevo;
Asignar = Copia;
} else {
double Exponente = (double)abs(Nuevo - Costo_anterior);
Exponente *= -1;
Exponente /= Temperatura;
if(exp(Exponente) < Decimal(Aleatorio)){
Costo_anterior = Nuevo;
Asignar = Copia;
}
}
Temperatura *= Enfriador;
/*cout<<Costo_anterior<<"\n";
for(auto E: Asignar) cout<<Dulces[E]<<" ";
cout<<"\n"<<Temperatura<<"\n";*/
}
cout<<Costo(Asignar)<<"\n";
for(int i = 0; i < n; i++){
cout<<Dulces[Asignar[i]]<<" ";
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
4 ms |
348 KB |
jury has better answer |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
6 ms |
348 KB |
jury has better answer |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
348 KB |
jury has better answer |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
3 ms |
348 KB |
jury has better answer |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
348 KB |
jury has better answer |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
6 ms |
604 KB |
jury has better answer |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
6 ms |
348 KB |
jury has better answer |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
6 ms |
604 KB |
jury has better answer |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
6 ms |
348 KB |
jury has better answer |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
6 ms |
348 KB |
jury has better answer |
2 |
Halted |
0 ms |
0 KB |
- |