From 439bf0808eadeee48bf1f6347eb253aa391857df Mon Sep 17 00:00:00 2001 From: JHLEE325 <82587652+JHLEE325@users.noreply.github.com> Date: Sat, 14 Feb 2026 15:01:20 +0900 Subject: [PATCH] =?UTF-8?q?[20260214]=20BOJ=20/=20G3=20/=20=EC=8A=A4?= =?UTF-8?q?=ED=8B=B0=EC=BB=A4=20=EB=B6=99=EC=9D=B4=EA=B8=B0=20/=20?= =?UTF-8?q?=EC=9D=B4=EC=A4=80=ED=9D=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...4 \353\266\231\354\235\264\352\270\260.md" | 88 +++++++++++++++++++ 1 file changed, 88 insertions(+) create mode 100644 "JHLEE325/202602/14 BOJ G3 \354\212\244\355\213\260\354\273\244 \353\266\231\354\235\264\352\270\260.md" diff --git "a/JHLEE325/202602/14 BOJ G3 \354\212\244\355\213\260\354\273\244 \353\266\231\354\235\264\352\270\260.md" "b/JHLEE325/202602/14 BOJ G3 \354\212\244\355\213\260\354\273\244 \353\266\231\354\235\264\352\270\260.md" new file mode 100644 index 00000000..b613333b --- /dev/null +++ "b/JHLEE325/202602/14 BOJ G3 \354\212\244\355\213\260\354\273\244 \353\266\231\354\235\264\352\270\260.md" @@ -0,0 +1,88 @@ +```java +import java.io.*; +import java.util.*; + +public class Main { + + static int N, M, K; + static int[][] note; + static int R, C; + static int[][] sticker; + + 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()); + + note = new int[N][M]; + + for (int s = 0; s < K; s++) { + st = new StringTokenizer(br.readLine()); + R = Integer.parseInt(st.nextToken()); + C = Integer.parseInt(st.nextToken()); + sticker = new int[R][C]; + + for (int i = 0; i < R; i++) { + st = new StringTokenizer(br.readLine()); + for (int j = 0; j < C; j++) sticker[i][j] = Integer.parseInt(st.nextToken()); + } + + for (int d = 0; d < 4; d++) { + if (tryAttach()) break; + rotate(); + } + } + + int count = 0; + for (int i = 0; i < N; i++) { + for (int j = 0; j < M; j++) if (note[i][j] == 1) count++; + } + System.out.println(count); + } + + static boolean tryAttach() { + for (int i = 0; i <= N - R; i++) { + for (int j = 0; j <= M - C; j++) { + if (canAttach(i, j)) { + attach(i, j); + return true; + } + } + } + return false; + } + + static boolean canAttach(int y, int x) { + for (int i = 0; i < R; i++) { + for (int j = 0; j < C; j++) { + if (sticker[i][j] == 1 && note[y + i][x + j] == 1) return false; + } + } + return true; + } + + static void attach(int y, int x) { + for (int i = 0; i < R; i++) { + for (int j = 0; j < C; j++) { + if (sticker[i][j] == 1) note[y + i][x + j] = 1; + } + } + } + + static void rotate() { + int[][] temp = new int[C][R]; + for (int i = 0; i < R; i++) { + for (int j = 0; j < C; j++) { + temp[j][R - 1 - i] = sticker[i][j]; + } + } + sticker = temp; + int t = R; + R = C; + C = t; + } +} +```