Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 70 additions & 0 deletions zinnnn37/202511/28 BOJ G4 직사각형과 쿼리.md
Original file line number Diff line number Diff line change
@@ -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();
}

}
```
34 changes: 34 additions & 0 deletions zinnnn37/202512/1 BOJ G5 Contact.md
Original file line number Diff line number Diff line change
@@ -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();
}

}
```