Skip to content

Commit 28640f1

Browse files
committed
[20260408] BOJ / G5 / Z / 김민진
1 parent 55a5f71 commit 28640f1

1 file changed

Lines changed: 63 additions & 0 deletions

File tree

zinnnn37/202604/8 BOJ G5 Z.md

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
```java
2+
import java.io.*;
3+
import java.util.StringTokenizer;
4+
5+
public class BJ_1074_Z {
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 StringTokenizer st;
10+
11+
private static int N, R, C, ans;
12+
13+
public static void main(String[] args) throws IOException {
14+
init();
15+
sol();
16+
}
17+
18+
private static void init() throws IOException {
19+
st = new StringTokenizer(br.readLine());
20+
N = Integer.parseInt(st.nextToken());
21+
R = Integer.parseInt(st.nextToken());
22+
C = Integer.parseInt(st.nextToken());
23+
}
24+
25+
private static void sol() throws IOException {
26+
rec((int) Math.pow(2, N), R, C);
27+
28+
bw.write(ans + "");
29+
bw.flush();
30+
bw.close();
31+
br.close();
32+
}
33+
34+
private static void rec(int size, int r, int c) {
35+
if (size == 1) {
36+
return;
37+
}
38+
39+
int half = size / 2;
40+
41+
// 좌상
42+
if (r < half && c < half) {
43+
rec(half, r, c);
44+
}
45+
// 좌하
46+
else if (r < half) {
47+
ans += size * size / 4;
48+
rec(half, r, c - half);
49+
}
50+
// 우상
51+
else if (c < half) {
52+
ans += (size * size / 4) * 2;
53+
rec(half, r - half, c);
54+
}
55+
// 우하
56+
else {
57+
ans += (size * size / 4) * 3;
58+
rec(half, r - half, c - half);
59+
}
60+
}
61+
62+
}
63+
```

0 commit comments

Comments
 (0)