Skip to content

Commit 5e1a0cc

Browse files
committed
[D4] Title: [S/W 문제해결 기본] 7일차 - 미로1, Time: 113 ms, Memory: 28,032 KB -BaekjoonHub
1 parent f0dc131 commit 5e1a0cc

2 files changed

Lines changed: 103 additions & 0 deletions

File tree

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# [D4] [S/W 문제해결 기본] 7일차 - 미로1 - 1226
2+
3+
[문제 링크](https://swexpertacademy.com/main/code/problem/problemDetail.do?contestProbId=AV14vXUqAGMCFAYD)
4+
5+
### 성능 요약
6+
7+
메모리: 28,032 KB, 시간: 113 ms, 코드길이: 1,529 Bytes
8+
9+
### 제출 일자
10+
11+
2026-09-02 11:39
12+
13+
14+
15+
> 출처: SW Expert Academy, https://swexpertacademy.com/main/code/problem/problemList.do
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
import java.util.*;
2+
import java.io.FileInputStream;
3+
4+
5+
class Solution
6+
{
7+
static int[] dr = {1,-1,0,0};
8+
static int[] dc = {0,0,1,-1};
9+
10+
public static void main(String args[]) throws Exception
11+
{
12+
13+
Scanner sc = new Scanner(System.in);
14+
15+
16+
for(int test_case = 1; test_case <= 10; test_case++)
17+
{
18+
int T;
19+
T=sc.nextInt();
20+
21+
// 길 0 벽 1 시작점 2 도착점 3
22+
23+
// 도달 가능 하면 1 불가능하면 0 출력
24+
int result = 0;
25+
26+
char[][] map = new char[16][16];
27+
28+
for(int i=0; i<16; i++) {
29+
map[i] = sc.next().toCharArray();
30+
}
31+
32+
33+
result = bfs(map);
34+
35+
36+
System.out.println("#" + test_case + " " + result);
37+
}
38+
39+
sc.close();
40+
}
41+
42+
public static int bfs(char[][] map) {
43+
44+
Queue<int[]> q = new LinkedList<>();
45+
boolean[][] isVisited = new boolean[16][16];
46+
int targetRow = -1;
47+
int targetCol = -1;
48+
49+
for(int i=0; i<16; i++) {
50+
for(int j=0; j<16; j++) {
51+
if(map[i][j] == '2') {
52+
q.add(new int[] {i,j});
53+
isVisited[i][j] = true;
54+
}
55+
if(map[i][j] == '3') {
56+
targetRow = i;
57+
targetCol = j;
58+
}
59+
}
60+
}
61+
62+
while(!q.isEmpty()) {
63+
int[] cur = q.poll();
64+
int row = cur[0];
65+
int col = cur[1];
66+
67+
if(row == targetRow && col == targetCol) return 1;
68+
69+
for(int i=0; i<4; i++) {
70+
71+
int nr = row + dr[i];
72+
int nc = col + dc[i];
73+
74+
if(nr >= 0 && nr < 16 && nc>=0 && nc<16
75+
&& map[nr][nc] != '1'
76+
&& !isVisited[nr][nc]) {
77+
q.add(new int[] {nr, nc});
78+
isVisited[nr][nc] = true;
79+
}
80+
}
81+
}
82+
83+
84+
85+
return 0;
86+
}
87+
88+
}

0 commit comments

Comments
 (0)