From 7467671aa30ce206aae3b1622ddd561779c18097 Mon Sep 17 00:00:00 2001 From: JHLEE325 <82587652+JHLEE325@users.noreply.github.com> Date: Fri, 23 Jan 2026 13:13:35 +0900 Subject: [PATCH 1/2] =?UTF-8?q?[20250123]=20BOJ=20/=20G4=20/=20=EB=B0=B0?= =?UTF-8?q?=EC=97=B4=20=EB=8F=8C=EB=A6=AC=EA=B8=B0=204=20/=20=EC=9D=B4?= =?UTF-8?q?=EC=A4=80=ED=9D=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...\353\217\214\353\246\254\352\270\260 4.md" | 107 ++++++++++++++++++ 1 file changed, 107 insertions(+) create mode 100644 "JHLEE325/202601/23 BOJ G4 \353\260\260\354\227\264 \353\217\214\353\246\254\352\270\260 4.md" diff --git "a/JHLEE325/202601/23 BOJ G4 \353\260\260\354\227\264 \353\217\214\353\246\254\352\270\260 4.md" "b/JHLEE325/202601/23 BOJ G4 \353\260\260\354\227\264 \353\217\214\353\246\254\352\270\260 4.md" new file mode 100644 index 00000000..fea010e9 --- /dev/null +++ "b/JHLEE325/202601/23 BOJ G4 \353\260\260\354\227\264 \353\217\214\353\246\254\352\270\260 4.md" @@ -0,0 +1,107 @@ +```java +import java.io.*; +import java.util.*; + +public class Main { + static int N, M, K; + static int[][] originalBoard; + static Operation[] ops; + static boolean[] visited; + static int[] p; + static int minVal = Integer.MAX_VALUE; + + static class Operation { + int r, c, s; + Operation(int r, int c, int s) { + this.r = r; this.c = c; this.s = s; + } + } + + public static void main(String[] args) throws IOException { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + StringTokenizer st = new StringTokenizer(br.readLine()); + + N = Integer.parseInt(st.nextToken()); + M = Integer.parseInt(st.nextToken()); + K = Integer.parseInt(st.nextToken()); + + originalBoard = new int[N + 1][M + 1]; + for (int i = 1; i <= N; i++) { + st = new StringTokenizer(br.readLine()); + for (int j = 1; j <= M; j++) { + originalBoard[i][j] = Integer.parseInt(st.nextToken()); + } + } + + ops = new Operation[K]; + for (int i = 0; i < K; i++) { + st = new StringTokenizer(br.readLine()); + ops[i] = new Operation( + Integer.parseInt(st.nextToken()), + Integer.parseInt(st.nextToken()), + Integer.parseInt(st.nextToken()) + ); + } + + visited = new boolean[K]; + p = new int[K]; + permutation(0); + + System.out.println(minVal); + } + + static void permutation(int cnt) { + if (cnt == K) { + int[][] copyBoard = copy(); + for (int i = 0; i < K; i++) { + rotate(copyBoard, ops[p[i]]); + } + calculateMin(copyBoard); + return; + } + for (int i = 0; i < K; i++) { + if (visited[i]) continue; + visited[i] = true; + p[cnt] = i; + permutation(cnt + 1); + visited[i] = false; + } + } + + static void rotate(int[][] board, Operation op) { + int r = op.r; + int c = op.c; + int s = op.s; + + for (int i = 1; i <= s; i++) { + int top = r - i; + int left = c - i; + int bottom = r + i; + int right = c + i; + + int temp = board[top][left]; + + for (int row = top; row < bottom; row++) board[row][left] = board[row + 1][left]; + for (int col = left; col < right; col++) board[bottom][col] = board[bottom][col + 1]; + for (int row = bottom; row > top; row--) board[row][right] = board[row - 1][right]; + for (int col = right; col > left + 1; col--) board[top][col] = board[top][col - 1]; + + board[top][left + 1] = temp; + } + } + + static int[][] copy() { + int[][] res = new int[N + 1][M + 1]; + for (int i = 1; i <= N; i++) res[i] = originalBoard[i].clone(); + return res; + } + + static void calculateMin(int[][] board) { + for (int i = 1; i <= N; i++) { + int sum = 0; + for (int j = 1; j <= M; j++) sum += board[i][j]; + minVal = Math.min(minVal, sum); + } + } +} +``` From 51af268b718de79178b83ee6e7dcd05651e5ae91 Mon Sep 17 00:00:00 2001 From: JHLEE325 <82587652+JHLEE325@users.noreply.github.com> Date: Fri, 23 Jan 2026 13:14:32 +0900 Subject: [PATCH 2/2] =?UTF-8?q?[20260123]=20BOJ=20/=20G4=20/=20=EB=B0=B0?= =?UTF-8?q?=EC=97=B4=20=EB=8F=8C=EB=A6=AC=EA=B8=B0=204=20/=20=EC=9D=B4?= =?UTF-8?q?=EC=A4=80=ED=9D=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...60\260\354\227\264 \353\217\214\353\246\254\352\270\260 4.md" | 1 + 1 file changed, 1 insertion(+) diff --git "a/JHLEE325/202601/23 BOJ G4 \353\260\260\354\227\264 \353\217\214\353\246\254\352\270\260 4.md" "b/JHLEE325/202601/23 BOJ G4 \353\260\260\354\227\264 \353\217\214\353\246\254\352\270\260 4.md" index fea010e9..5a8435d9 100644 --- "a/JHLEE325/202601/23 BOJ G4 \353\260\260\354\227\264 \353\217\214\353\246\254\352\270\260 4.md" +++ "b/JHLEE325/202601/23 BOJ G4 \353\260\260\354\227\264 \353\217\214\353\246\254\352\270\260 4.md" @@ -2,6 +2,7 @@ import java.io.*; import java.util.*; + public class Main { static int N, M, K; static int[][] originalBoard;