Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 8 additions & 14 deletions solution/BOJ_14442_벽-부수고-이동하기2/ykm.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,15 @@
public class Main{
public static class node{
int x, y;
int move;
int wall;
int move; // 이동횟수
int wall; // 부슨 벽의 수

public node(int x, int y, int move, int wall){
this.x = x;
this.y = y;
this.move = move;
this.wall = wall;
}

@Override
public String toString() {
return "node [move=" + move + ", wall=" + wall + ", x=" + x + ", y=" + y + "]";
}
}

static int M;
Expand All @@ -43,16 +38,16 @@ public static void main(String[] args)throws IOException{
N = Integer.parseInt(st.nextToken());
K = Integer.parseInt(st.nextToken());
map = new char[M][N];
isVisited = new boolean[M][N][K+1]; // 위치, 부슨벽의 수
isVisited = new boolean[M][N][K+1]; // 위치 x,y , 부슨벽의 수

for(int i = 0 ; i<M; i++){
map[i] = br.readLine().toCharArray();
}

isVisited[0][0][0] = true;
Queue<node> q = new ArrayDeque<node>();
q.offer(new node(0,0,1,K));
q.offer(new node(0,0,1,0));

while(!q.isEmpty()){
node current = q.poll();

Expand All @@ -72,16 +67,15 @@ public static void main(String[] args)throws IOException{
continue;
}

if(isVisited[nextX][nextY][current.wall]){
continue;
}

if(map[nextX][nextY]=='1'){ // 벽
if(current.wall<K && !isVisited[nextX][nextY][current.wall+1]){ // 벽을 부슬수 있는 경우
isVisited[nextX][nextY][current.wall+1] = true;
q.offer(new node(nextX, nextY, current.move+1, current.wall+1));
}
}else{
if(isVisited[nextX][nextY][current.wall]){
continue;
}
isVisited[nextX][nextY][current.wall] = true;
q.offer(new node(nextX, nextY, current.move+1, current.wall));
}
Expand Down