From ef2ce6dd0032e70a8211ca64b65eb3cf307bac4f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=EB=AF=BC=EC=A7=84?= Date: Mon, 1 Dec 2025 13:50:55 +0900 Subject: [PATCH] =?UTF-8?q?[20251201]=20BOJ=20/=20G5=20/=20Contact=20/=20?= =?UTF-8?q?=EA=B9=80=EB=AF=BC=EC=A7=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...5\352\263\274 \354\277\274\353\246\254.md" | 70 +++++++++++++++++++ zinnnn37/202512/1 BOJ G5 Contact.md | 34 +++++++++ 2 files changed, 104 insertions(+) create mode 100644 "zinnnn37/202511/28 BOJ G4 \354\247\201\354\202\254\352\260\201\355\230\225\352\263\274 \354\277\274\353\246\254.md" create mode 100644 zinnnn37/202512/1 BOJ G5 Contact.md diff --git "a/zinnnn37/202511/28 BOJ G4 \354\247\201\354\202\254\352\260\201\355\230\225\352\263\274 \354\277\274\353\246\254.md" "b/zinnnn37/202511/28 BOJ G4 \354\247\201\354\202\254\352\260\201\355\230\225\352\263\274 \354\277\274\353\246\254.md" new file mode 100644 index 00000000..f48f558f --- /dev/null +++ "b/zinnnn37/202511/28 BOJ G4 \354\247\201\354\202\254\352\260\201\355\230\225\352\263\274 \354\277\274\353\246\254.md" @@ -0,0 +1,70 @@ +```java +import java.io.*; +import java.util.StringTokenizer; + +public class BJ_14846_직사각형과_쿼리 { + + private static final BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + private static final BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out)); + private static final StringBuilder sb = new StringBuilder(); + private static StringTokenizer st; + + private static int N, Q, ans; + private static int[][] nums; + private static int[][][] prefix; + + public static void main(String[] args) throws IOException { + init(); + sol(); + } + + private static void init() throws IOException { + N = Integer.parseInt(br.readLine()); + + nums = new int[N + 1][N + 1]; + for (int i = 1; i <= N; i++) { + st = new StringTokenizer(br.readLine()); + for (int j = 1; j <= N; j++) { + nums[i][j] = Integer.parseInt(st.nextToken()); + } + } + + prefix = new int[N + 1][N + 1][11]; + for (int i = 1; i <= N; i++) { + for (int j = 1; j <= N; j++) { + for (int a = 0; a <= 10; a++) { + prefix[i][j][a] += prefix[i - 1][j][a]; + prefix[i][j][a] += prefix[i][j - 1][a]; + prefix[i][j][a] -= prefix[i - 1][j - 1][a]; + } + prefix[i][j][nums[i][j]]++; + } + } + Q = Integer.parseInt(br.readLine()); + } + + private static void sol() throws IOException { + while (Q-- > 0) { + st = new StringTokenizer(br.readLine()); + + int x1 = Integer.parseInt(st.nextToken()) - 1; + int y1 = Integer.parseInt(st.nextToken()) - 1; + int x2 = Integer.parseInt(st.nextToken()); + int y2 = Integer.parseInt(st.nextToken()); + + ans = 0; + for (int k = 1; k <= 10; k++) { + int count = prefix[x2][y2][k] - prefix[x1][y2][k] + - prefix[x2][y1][k] + prefix[x1][y1][k]; + if (count > 0) ans++; + } + sb.append(ans).append("\n"); + } + bw.write(sb.toString()); + bw.flush(); + bw.close(); + br.close(); + } + +} +``` \ No newline at end of file diff --git a/zinnnn37/202512/1 BOJ G5 Contact.md b/zinnnn37/202512/1 BOJ G5 Contact.md new file mode 100644 index 00000000..f9bed4df --- /dev/null +++ b/zinnnn37/202512/1 BOJ G5 Contact.md @@ -0,0 +1,34 @@ +```java +import java.io.*; +import java.util.regex.Pattern; + +public class BJ_1013_Contact { + + private static final BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + private static final BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out)); + private static final StringBuilder sb = new StringBuilder(); + + private static int N; + private static String input; + + public static void main(String[] args) throws IOException { + sol(); + } + + private static void sol() throws IOException { + N = Integer.parseInt(br.readLine()); + + while (N-- > 0) { + input = br.readLine(); + + boolean res = Pattern.matches("(100+1+|01)+", input); + sb.append(res ? "YES\n" : "NO\n"); + } + bw.write(sb.toString()); + bw.flush(); + bw.close(); + br.close(); + } + +} +``` \ No newline at end of file