Skip to content

Commit 0c12960

Browse files
authored
[20251228] BOJ / G5 / 행성 탐사 / 한종욱
1 parent 50b2b6f commit 0c12960

File tree

1 file changed

+67
-0
lines changed

1 file changed

+67
-0
lines changed
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
```
2+
import java.io.*;
3+
import java.util.*;
4+
5+
public class Main {
6+
private static final BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
7+
private static final BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
8+
private static char[][] map;
9+
private static int[][] sumJ, sumO, sumI;
10+
private static int M, N, K;
11+
12+
public static void main(String[] args) throws IOException {
13+
init();
14+
15+
while (K-->0) {
16+
StringTokenizer st = new StringTokenizer(br.readLine());
17+
int a = Integer.parseInt(st.nextToken());
18+
int b = Integer.parseInt(st.nextToken());
19+
int c = Integer.parseInt(st.nextToken());
20+
int d = Integer.parseInt(st.nextToken());
21+
22+
bw.write(count(sumJ, a, b, c, d) + " " + count(sumO, a, b, c, d) + " " + count(sumI, a, b, c, d) + "\n");
23+
}
24+
bw.flush();
25+
bw.close();
26+
br.close();
27+
}
28+
29+
private static void init() throws IOException {
30+
StringTokenizer st = new StringTokenizer(br.readLine());
31+
M = Integer.parseInt(st.nextToken());
32+
N = Integer.parseInt(st.nextToken());
33+
K = Integer.parseInt(br.readLine());
34+
35+
map = new char[M+1][N+1];
36+
sumJ = new int[M+1][N+1];
37+
sumO = new int[M+1][N+1];
38+
sumI = new int[M+1][N+1];
39+
40+
for (int i = 1; i <= M; i++) {
41+
char[] input = br.readLine().toCharArray();
42+
for (int j = 1; j <= N; j++) {
43+
map[i][j] = input[j-1];
44+
}
45+
}
46+
47+
for (int i = 1; i <= M; i++) {
48+
for (int j = 1; j <= N; j++) {
49+
sumJ[i][j] = sumJ[i-1][j] + sumJ[i][j-1] - sumJ[i-1][j-1];
50+
sumO[i][j] = sumO[i-1][j] + sumO[i][j-1] - sumO[i-1][j-1];
51+
sumI[i][j] = sumI[i-1][j] + sumI[i][j-1] - sumI[i-1][j-1];
52+
if (map[i][j] == 'J') {
53+
sumJ[i][j]++;
54+
} else if (map[i][j] == 'O') {
55+
sumO[i][j]++;
56+
} else {
57+
sumI[i][j]++;
58+
}
59+
}
60+
}
61+
}
62+
63+
private static int count(int[][] sum, int a, int b, int c, int d) {
64+
return sum[c][d] - sum[a-1][d] - sum[c][b-1] + sum[a-1][b-1];
65+
}
66+
}
67+
```

0 commit comments

Comments
 (0)