From d6a3248ea096fdda68856215865ef20a10a20b18 Mon Sep 17 00:00:00 2001 From: Jinyeong Seol Date: Sat, 14 Jun 2025 23:26:36 +0900 Subject: [PATCH 1/2] =?UTF-8?q?[20250613]=20BOJ=20/=20G4=20/=20N-Queen=20/?= =?UTF-8?q?=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/202506/14 BOJ G4 N-Queen.md | 44 +++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 Seol-JY/202506/14 BOJ G4 N-Queen.md diff --git a/Seol-JY/202506/14 BOJ G4 N-Queen.md b/Seol-JY/202506/14 BOJ G4 N-Queen.md new file mode 100644 index 00000000..424ea77a --- /dev/null +++ b/Seol-JY/202506/14 BOJ G4 N-Queen.md @@ -0,0 +1,44 @@ +```java +import java.io.*; + +public class Main { + private static int N; + private static int count = 0; + private static int cols = 0; + private static int diag1 = 0; + private static int diag2 = 0; + + public static void main(String[] args) throws IOException { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + N = Integer.parseInt(br.readLine()); + + solve(0); + System.out.println(count); + } + + private static void solve(int row) { + if (row == N) { + count++; + return; + } + + for (int col = 0; col < N; col++) { + int colBit = 1 << col; + int diag1Bit = 1 << (row + col); + int diag2Bit = 1 << (row - col + N - 1); + + if ((cols & colBit) == 0 && (diag1 & diag1Bit) == 0 && (diag2 & diag2Bit) == 0) { + cols |= colBit; + diag1 |= diag1Bit; + diag2 |= diag2Bit; + + solve(row + 1); + + cols &= ~colBit; + diag1 &= ~diag1Bit; + diag2 &= ~diag2Bit; + } + } + } +} +``` From 8d194d2de4cd53196f3f0b53f99544de5e2fbcbc Mon Sep 17 00:00:00 2001 From: Jinyeong Seol Date: Sat, 14 Jun 2025 23:27:21 +0900 Subject: [PATCH 2/2] =?UTF-8?q?[20250614]=20BOJ=20/=20G4=20/=20N-Queen=20/?= =?UTF-8?q?=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/202506/14 BOJ G4 N-Queen.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Seol-JY/202506/14 BOJ G4 N-Queen.md b/Seol-JY/202506/14 BOJ G4 N-Queen.md index 424ea77a..c7e07e0e 100644 --- a/Seol-JY/202506/14 BOJ G4 N-Queen.md +++ b/Seol-JY/202506/14 BOJ G4 N-Queen.md @@ -41,4 +41,4 @@ public class Main { } } } -``` +```