TOPIC

WA 20% ???

Ygor Ribeiro asked 3 years ago

``````#include<bits/stdc++.h>

using namespace std;

#define oo 0x3f3f3f

int bfs(int ini, int fim){
int dist[100010];
memset(dist, oo, sizeof dist);
dist[ini] = 0;
queue<int> fila;
fila.push(ini);
while(!fila.empty()){
int x = fila.front();
fila.pop();
int y = x * 2;
//printf("%d\n",x);
if(dist[y] > dist[x] + 1 && y >= 0 && y < 10001){
dist[y] = dist[x] + 1;
fila.push(y);
}
y = x * 3;
if(dist[y] > dist[x] + 1 && y >= 0 && y < 10001){
dist[y] = dist[x] + 1;
fila.push(y);
}
y = x / 2;
if(dist[y] > dist[x] + 1 && y >= 0 && y < 10001){
dist[y] = dist[x] + 1;
fila.push(y);
}
y = x / 3;
if(dist[y] > dist[x] + 1 && y >= 0 && y < 10001){
dist[y] = dist[x] + 1;
fila.push(y);
}
y = x + 7;
if(dist[y] > dist[x] + 1 && y >= 0 && y < 10001){
dist[y] = dist[x] + 1;
fila.push(y);
}
y = x - 7;
if(dist[y] > dist[x] + 1 && y >= 0 && y < 10001){
dist[y] = dist[x] + 1;
fila.push(y);
}

}
return dist[fim];
}

int main(){
int a,b;
scanf("%d%d",&a,&b);
printf("%d\n",bfs(a,b));

return 0;
}
``````

Remember not post solutions. Your post may be reviewed by our moderators.