Skip to content

Commit ef2ce6d

Browse files
committed
[20251201] BOJ / G5 / Contact / 김민진
1 parent 2c922d2 commit ef2ce6d

File tree

2 files changed

+104
-0
lines changed

2 files changed

+104
-0
lines changed
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
```java
2+
import java.io.*;
3+
import java.util.StringTokenizer;
4+
5+
public class BJ_14846_직사각형과_쿼리 {
6+
7+
private static final BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
8+
private static final BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
9+
private static final StringBuilder sb = new StringBuilder();
10+
private static StringTokenizer st;
11+
12+
private static int N, Q, ans;
13+
private static int[][] nums;
14+
private static int[][][] prefix;
15+
16+
public static void main(String[] args) throws IOException {
17+
init();
18+
sol();
19+
}
20+
21+
private static void init() throws IOException {
22+
N = Integer.parseInt(br.readLine());
23+
24+
nums = new int[N + 1][N + 1];
25+
for (int i = 1; i <= N; i++) {
26+
st = new StringTokenizer(br.readLine());
27+
for (int j = 1; j <= N; j++) {
28+
nums[i][j] = Integer.parseInt(st.nextToken());
29+
}
30+
}
31+
32+
prefix = new int[N + 1][N + 1][11];
33+
for (int i = 1; i <= N; i++) {
34+
for (int j = 1; j <= N; j++) {
35+
for (int a = 0; a <= 10; a++) {
36+
prefix[i][j][a] += prefix[i - 1][j][a];
37+
prefix[i][j][a] += prefix[i][j - 1][a];
38+
prefix[i][j][a] -= prefix[i - 1][j - 1][a];
39+
}
40+
prefix[i][j][nums[i][j]]++;
41+
}
42+
}
43+
Q = Integer.parseInt(br.readLine());
44+
}
45+
46+
private static void sol() throws IOException {
47+
while (Q-- > 0) {
48+
st = new StringTokenizer(br.readLine());
49+
50+
int x1 = Integer.parseInt(st.nextToken()) - 1;
51+
int y1 = Integer.parseInt(st.nextToken()) - 1;
52+
int x2 = Integer.parseInt(st.nextToken());
53+
int y2 = Integer.parseInt(st.nextToken());
54+
55+
ans = 0;
56+
for (int k = 1; k <= 10; k++) {
57+
int count = prefix[x2][y2][k] - prefix[x1][y2][k]
58+
- prefix[x2][y1][k] + prefix[x1][y1][k];
59+
if (count > 0) ans++;
60+
}
61+
sb.append(ans).append("\n");
62+
}
63+
bw.write(sb.toString());
64+
bw.flush();
65+
bw.close();
66+
br.close();
67+
}
68+
69+
}
70+
```
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
```java
2+
import java.io.*;
3+
import java.util.regex.Pattern;
4+
5+
public class BJ_1013_Contact {
6+
7+
private static final BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
8+
private static final BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
9+
private static final StringBuilder sb = new StringBuilder();
10+
11+
private static int N;
12+
private static String input;
13+
14+
public static void main(String[] args) throws IOException {
15+
sol();
16+
}
17+
18+
private static void sol() throws IOException {
19+
N = Integer.parseInt(br.readLine());
20+
21+
while (N-- > 0) {
22+
input = br.readLine();
23+
24+
boolean res = Pattern.matches("(100+1+|01)+", input);
25+
sb.append(res ? "YES\n" : "NO\n");
26+
}
27+
bw.write(sb.toString());
28+
bw.flush();
29+
bw.close();
30+
br.close();
31+
}
32+
33+
}
34+
```

0 commit comments

Comments
 (0)