From d75e1c6a9e0db0df7f5866d6411040d2d74c125f Mon Sep 17 00:00:00 2001 From: Jinyeong Seol Date: Tue, 28 Oct 2025 23:53:28 +0900 Subject: [PATCH] =?UTF-8?q?[20251028]=20BOJ=20/=20G4=20/=20=EC=A3=BC?= =?UTF-8?q?=EC=82=AC=EC=9C=84=20=EA=B5=B4=EB=A6=AC=EA=B8=B0=20/=20?= =?UTF-8?q?=EC=84=A4=EC=A7=84=EC=98=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...4 \352\265\264\353\246\254\352\270\260.md" | 154 ++++++++++++++++++ 1 file changed, 154 insertions(+) create mode 100644 "Seol-JY/202510/28 BOJ G4 \354\243\274\354\202\254\354\234\204 \352\265\264\353\246\254\352\270\260.md" diff --git "a/Seol-JY/202510/28 BOJ G4 \354\243\274\354\202\254\354\234\204 \352\265\264\353\246\254\352\270\260.md" "b/Seol-JY/202510/28 BOJ G4 \354\243\274\354\202\254\354\234\204 \352\265\264\353\246\254\352\270\260.md" new file mode 100644 index 00000000..4918e86f --- /dev/null +++ "b/Seol-JY/202510/28 BOJ G4 \354\243\274\354\202\254\354\234\204 \352\265\264\353\246\254\352\270\260.md" @@ -0,0 +1,154 @@ +```java +import java.io.*; +import java.util.*; + +public class Main { + static class Dice { + int top, bottom, front, back, left, right; + + public Dice() { + this.top = 0; + this.bottom = 0; + this.front = 0; + this.back = 0; + this.left = 0; + this.right = 0; + } + + public void rollEast() { + int temp = top; + top = left; + left = bottom; + bottom = right; + right = temp; + } + + public void rollWest() { + int temp = top; + top = right; + right = bottom; + bottom = left; + left = temp; + } + + public void rollNorth() { + int temp = top; + top = front; + front = bottom; + bottom = back; + back = temp; + } + + public void rollSouth() { + int temp = top; + top = back; + back = bottom; + bottom = front; + front = temp; + } + + public int getTop() { + return top; + } + + public int getBottom() { + return bottom; + } + + public void setBottom(int value) { + this.bottom = value; + } + } + + static class Position { + int x, y; + + public Position(int x, int y) { + this.x = x; + this.y = y; + } + + public Position move(int direction) { + switch(direction) { + case 1: + return new Position(x, y + 1); + case 2: + return new Position(x, y - 1); + case 3: + return new Position(x - 1, y); + case 4: + return new Position(x + 1, y); + default: + return this; + } + } + + public boolean isValid(int n, int m) { + return x >= 0 && x < n && y >= 0 && y < m; + } + } + + public static void main(String[] args) throws IOException { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out)); + + StringTokenizer st = new StringTokenizer(br.readLine()); + int n = Integer.parseInt(st.nextToken()); + int m = Integer.parseInt(st.nextToken()); + int x = Integer.parseInt(st.nextToken()); + int y = Integer.parseInt(st.nextToken()); + int k = Integer.parseInt(st.nextToken()); + + int[][] map = new int[n][m]; + for (int i = 0; i < n; i++) { + st = new StringTokenizer(br.readLine()); + for (int j = 0; j < m; j++) { + map[i][j] = Integer.parseInt(st.nextToken()); + } + } + + Dice dice = new Dice(); + Position pos = new Position(x, y); + + st = new StringTokenizer(br.readLine()); + for (int i = 0; i < k; i++) { + int direction = Integer.parseInt(st.nextToken()); + Position nextPos = pos.move(direction); + + if (!nextPos.isValid(n, m)) { + continue; + } + + switch(direction) { + case 1: + dice.rollEast(); + break; + case 2: + dice.rollWest(); + break; + case 3: + dice.rollNorth(); + break; + case 4: + dice.rollSouth(); + break; + } + + pos = nextPos; + + if (map[pos.x][pos.y] == 0) { + map[pos.x][pos.y] = dice.getBottom(); + } else { + dice.setBottom(map[pos.x][pos.y]); + map[pos.x][pos.y] = 0; + } + + bw.write(dice.getTop() + "\n"); + } + + bw.flush(); + bw.close(); + br.close(); + } +} +```