diff --git "a/suyeun84/202502/11 BOJ G5 \353\263\264\354\235\264\354\240\200 1\355\230\270.md" "b/suyeun84/202502/11 BOJ G5 \353\263\264\354\235\264\354\240\200 1\355\230\270.md" new file mode 100644 index 00000000..af1f08a5 --- /dev/null +++ "b/suyeun84/202502/11 BOJ G5 \353\263\264\354\235\264\354\240\200 1\355\230\270.md" @@ -0,0 +1,75 @@ +```java +import java.util.*; +import java.io.*; + +class Solution +{ + static int N; + static int M; + static char[][] board; + public static void main(String[] args) throws Exception{ + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + StringTokenizer st = new StringTokenizer(br.readLine()); + N = Integer.parseInt(st.nextToken()); + M = Integer.parseInt(st.nextToken()); + board = new char[N][M]; + for (int i = 0; i < N; i++) { + String line = br.readLine(); + for (int j = 0; j < M; j++) { + board[i][j] = line.charAt(j); + } + } + st = new StringTokenizer(br.readLine()); + int PR = Integer.parseInt(st.nextToken()); + int PC = Integer.parseInt(st.nextToken()); + + int[][] dir = new int[][] {{1,0},{-1,0},{0,1},{0,-1}}; //D, U, R, L + char cdir = 'U'; + int answer = 0; + for (int i = 0; i < 4; i++) { + int[] d = dir[i]; + int res = check(PR-1, PC-1, d); + if (res > answer) { + if (i == 0) cdir = 'D'; + else if (i == 1) cdir = 'U'; + else if (i == 2) cdir = 'R'; + else cdir = 'L'; + answer = res; + } + if (res == Integer.MAX_VALUE) { + if (i == 1 && (cdir == 'R' || cdir == 'D' || cdir == 'L')) cdir = 'U'; + else if (i == 2 && (cdir == 'D' || cdir == 'L')) cdir = 'R'; + else if (i == 0 && cdir == 'L') cdir = 'D'; + } + } + System.out.println(cdir); + if (answer == Integer.MAX_VALUE) { + System.out.println("Voyager"); + } else { + System.out.println(answer); + } + } + + public static int check(int cy, int cx, int[] d) { + int cnt = 1; + while(true) { + cy += d[0]; + cx += d[1]; + if (cnt > N*M*2) return Integer.MAX_VALUE; + if (cy < 0 || cy >= N || cx < 0 || cx >= M || board[cy][cx] == 'C') break; + if (board[cy][cx] == '/') { + int temp = d[0]; + d[0] = d[1]*-1; + d[1] = temp*-1; + }else if (board[cy][cx] == '\\') { + int temp = d[0]; + d[0] = d[1]; + d[1] = temp; + } + cnt += 1; + } + return cnt; + } +} + +```