From 4f8289a90ff04342abf6c29bab037d23195b7c86 Mon Sep 17 00:00:00 2001 From: Jinyeong Seol Date: Wed, 12 Feb 2025 16:43:36 +0900 Subject: [PATCH] =?UTF-8?q?[20250212]=20BOJ=20/=20=EA=B3=A8=EB=93=9C5=20/?= =?UTF-8?q?=20Z=20/=20=EC=84=A4=EC=A7=84=EC=98=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Seol-JY/202502/12 BOJ G5 Z | 52 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 Seol-JY/202502/12 BOJ G5 Z diff --git a/Seol-JY/202502/12 BOJ G5 Z b/Seol-JY/202502/12 BOJ G5 Z new file mode 100644 index 00000000..43514d16 --- /dev/null +++ b/Seol-JY/202502/12 BOJ G5 Z @@ -0,0 +1,52 @@ +```java +import java.io.*; +import java.util.*; +public class Main { + static int R, C; + public static void main(String[] args) throws IOException { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + StringTokenizer st = new StringTokenizer(br.readLine()); + int N = nextInt(st); + R = nextInt(st); + C = nextInt(st); + + recur(N, 0L); + } + + private static void recur(int n, long startValue) { + int quad = determine(n); + long newStartValue = startValue + quad * (1L << (2*(n-1))); + + if (n == 1){ + System.out.println(newStartValue); + return; + } + + recur(n-1, newStartValue); + } + + private static int determine(int n) { + int stand = 1 << (n-1); + + if (R < stand && C < stand) { + return 0; + } + if (R < stand && C >= stand) { + C -= stand; + return 1; + } + if (R >= stand && C < stand) { + R -= stand; + return 2; + } + C -= stand; + R -= stand; + + return 3; + } + + private static int nextInt(StringTokenizer st) { + return Integer.parseInt(st.nextToken()); + } +} +```