From 980dc24987b4093030e9a5ee3fff772a26b8414e Mon Sep 17 00:00:00 2001 From: Jinyeong Seol Date: Thu, 26 Jun 2025 23:48:52 +0900 Subject: [PATCH 1/2] =?UTF-8?q?[20250626]=20BOJ=20/=20G1=20/=202048=20(Eas?= =?UTF-8?q?y)=20/=20=EC=84=A4=EC=A7=84=EC=98=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Seol-JY/202505/26 BOJ G1 2048 (Easy).md | 133 ++++++++++++++++++++++++ 1 file changed, 133 insertions(+) create mode 100644 Seol-JY/202505/26 BOJ G1 2048 (Easy).md diff --git a/Seol-JY/202505/26 BOJ G1 2048 (Easy).md b/Seol-JY/202505/26 BOJ G1 2048 (Easy).md new file mode 100644 index 00000000..9ef465cc --- /dev/null +++ b/Seol-JY/202505/26 BOJ G1 2048 (Easy).md @@ -0,0 +1,133 @@ +```java +import java.io.BufferedReader; +import java.io.InputStreamReader; +import java.util.StringTokenizer; + +public class Main { + + static int n, answer; + static int[][] map; + + public static void main(String[] args) throws Exception { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + n = Integer.parseInt(br.readLine()); + answer = 0; + map = new int[n][n]; + + for (int i = 0; i < n; i++) { + StringTokenizer st = new StringTokenizer(br.readLine()); + for (int j = 0; j < n; j++) { + map[i][j] = Integer.parseInt(st.nextToken()); + } + } + + game(0); + System.out.println(answer); + } + + public static void game(int count) { + if (count == 5) { + findMax(); + return; + } + + int[][] backup = new int[n][n]; + for (int i = 0; i < n; i++) { + backup[i] = map[i].clone(); + } + + for (int dir = 0; dir < 4; dir++) { + move(dir); + game(count + 1); + + for (int i = 0; i < n; i++) { + map[i] = backup[i].clone(); + } + } + } + + public static void move(int dir) { + if (dir == 0) { + for (int j = 0; j < n; j++) { + int index = 0; + int prev = 0; + for (int i = 0; i < n; i++) { + if (map[i][j] != 0) { + if (prev == map[i][j]) { + map[index - 1][j] = prev * 2; + prev = 0; + } else { + prev = map[i][j]; + map[index][j] = prev; + index++; + } + if (i != index - 1) map[i][j] = 0; + } + } + } + } else if (dir == 1) { + for (int j = 0; j < n; j++) { + int index = n - 1; + int prev = 0; + for (int i = n - 1; i >= 0; i--) { + if (map[i][j] != 0) { + if (prev == map[i][j]) { + map[index + 1][j] = prev * 2; + prev = 0; + } else { + prev = map[i][j]; + map[index][j] = prev; + index--; + } + if (i != index + 1) map[i][j] = 0; + } + } + } + } else if (dir == 2) { + for (int i = 0; i < n; i++) { + int index = 0; + int prev = 0; + for (int j = 0; j < n; j++) { + if (map[i][j] != 0) { + if (prev == map[i][j]) { + map[i][index - 1] = prev * 2; + prev = 0; + } else { + prev = map[i][j]; + map[i][index] = prev; + index++; + } + if (j != index - 1) map[i][j] = 0; + } + } + } + } else { + for (int i = 0; i < n; i++) { + int index = n - 1; + int prev = 0; + for (int j = n - 1; j >= 0; j--) { + if (map[i][j] != 0) { + if (prev == map[i][j]) { + map[i][index + 1] = prev * 2; + prev = 0; + } else { + prev = map[i][j]; + map[i][index] = prev; + index--; + } + if (j != index + 1) map[i][j] = 0; + } + } + } + } + } + + public static void findMax() { + for (int i = 0; i < n; i++) { + for (int j = 0; j < n; j++) { + answer = Math.max(answer, map[i][j]); + } + } + } +} +``` From cf87d5456d6e397c375c3e4e7029a886b833a216 Mon Sep 17 00:00:00 2001 From: Jinyeong Seol Date: Thu, 26 Jun 2025 23:50:07 +0900 Subject: [PATCH 2/2] =?UTF-8?q?[20250626]=20BOJ=20/=20G1=20/=202048=20(Eas?= =?UTF-8?q?y)=20/=20=EC=84=A4=EC=A7=84=EC=98=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Seol-JY/{202505 => 202506}/26 BOJ G1 2048 (Easy).md | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename Seol-JY/{202505 => 202506}/26 BOJ G1 2048 (Easy).md (100%) diff --git a/Seol-JY/202505/26 BOJ G1 2048 (Easy).md b/Seol-JY/202506/26 BOJ G1 2048 (Easy).md similarity index 100% rename from Seol-JY/202505/26 BOJ G1 2048 (Easy).md rename to Seol-JY/202506/26 BOJ G1 2048 (Easy).md