From 58468a68418cd7b32fcab19a18ce0251088ecdb1 Mon Sep 17 00:00:00 2001 From: songyc macbook Date: Sat, 2 Aug 2025 17:13:52 +0900 Subject: [PATCH] 20250802 baekjoon --- code_study/Baekjoon/java/_2178.java | 56 +++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 code_study/Baekjoon/java/_2178.java diff --git a/code_study/Baekjoon/java/_2178.java b/code_study/Baekjoon/java/_2178.java new file mode 100644 index 0000000..d7928be --- /dev/null +++ b/code_study/Baekjoon/java/_2178.java @@ -0,0 +1,56 @@ +import java.util.*; + +class Point{ + int x; + int y; + + Point(int x, int y){ + this.x = x; + this.y = y; + } +} + +public class _2178{ + public static void main(String[] args) { + Scanner sc = new Scanner(System.in); + String[] input = sc.nextLine().split(" "); + int N = Integer.parseInt(input[0]); + int M = Integer.parseInt(input[1]); + int[][] Meero = new int[N+1][M+1]; + int[][] visited = new int[N+1][M+1]; + Queue queue = new LinkedList<>(); + + for(int i=1; i<=N; i++){ + String[] line = sc.nextLine().split(""); + for(int j=1; j<=M; j++){ + Meero[i][j] = Integer.parseInt(line[j-1]); + } + } + + queue.add(new Point(1,1)); + visited[1][1] = 1; + int[] dx = {1,-1,0,0}; + int[] dy = {0,0,1,-1}; + + while(queue.size()!=0){ + Point curretPoint = queue.remove(); + int cx = curretPoint.x; + int cy = curretPoint.y; + if(cx == M && cy == N){ + System.out.println(visited[cy][cx]); + break; + } + for(int i=0; i<4; i++){ + int nx = cx + dx[i]; + int ny = cy + dy[i]; + if(0