From 2c922d22cba6d7fe7a5f79b2a0c167b9438a2068 Mon Sep 17 00:00:00 2001 From: zinnnn37 Date: Sat, 29 Nov 2025 13:09:11 +0900 Subject: [PATCH] =?UTF-8?q?[20251129]=20BOJ=20/=20G4=20/=20=EC=A7=81?= =?UTF-8?q?=EC=82=AC=EA=B0=81=ED=98=95=EA=B3=BC=20=EC=BF=BC=EB=A6=AC=20/?= =?UTF-8?q?=20=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 +++++++++++++++++++ 1 file changed, 70 insertions(+) create mode 100644 "zinnnn37/202511/29 BOJ G4 \354\247\201\354\202\254\352\260\201\355\230\225\352\263\274 \354\277\274\353\246\254.md" diff --git "a/zinnnn37/202511/29 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/29 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..04765921 --- /dev/null +++ "b/zinnnn37/202511/29 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 Main { + + 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