From 0fa707ddf013c5d7e168a7cefeeb10f1b9812f30 Mon Sep 17 00:00:00 2001 From: Jinyeong Seol Date: Thu, 10 Jul 2025 20:41:41 +0900 Subject: [PATCH] =?UTF-8?q?[20250710]=20BOJ=20/=20P4=20/=20=EB=B6=88=20?= =?UTF-8?q?=EB=81=84=EA=B8=B0=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 --- ... \353\266\210 \353\201\204\352\270\260.md" | 64 +++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 "Seol-JY/202507/10 BOJ P4 \353\266\210 \353\201\204\352\270\260.md" diff --git "a/Seol-JY/202507/10 BOJ P4 \353\266\210 \353\201\204\352\270\260.md" "b/Seol-JY/202507/10 BOJ P4 \353\266\210 \353\201\204\352\270\260.md" new file mode 100644 index 00000000..290558d9 --- /dev/null +++ "b/Seol-JY/202507/10 BOJ P4 \353\266\210 \353\201\204\352\270\260.md" @@ -0,0 +1,64 @@ +```java +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; + +public class Main { + static int[] map = new int[10]; + static int sum; + static int minToggle = Integer.MAX_VALUE; + + public static void main(String[] args) throws IOException { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + + for (int i = 0; i < 10; i++) { + String input = br.readLine(); + for (int j = 0; j < 10; j++) { + if (input.charAt(j) == 'O') { + map[i] |= (1 << j); + } + } + } + + for (int firstRow = 0; firstRow < (1 << 10); firstRow++) { + int[] tempMap = map.clone(); + int toggleCount = 0; + + for (int j = 0; j < 10; j++) { + if (isLightOn(firstRow, j)) { + toggle(tempMap, 0, j); + toggleCount++; + } + } + + for (int i = 1; i < 10; i++) { + for (int j = 0; j < 10; j++) { + if (isLightOn(tempMap[i - 1], j)) { + toggle(tempMap, i, j); + toggleCount++; + } + } + } + + if (tempMap[9] == 0) { + minToggle = Math.min(minToggle, toggleCount); + } + } + + System.out.println(minToggle == Integer.MAX_VALUE ? -1 : minToggle); + } + + static boolean isLightOn(int row, int col) { + return (row & (1 << col)) != 0; + } + + static void toggle(int[] map, int x, int y) { + map[x] ^= (1 << y); + + if (x > 0) map[x - 1] ^= (1 << y); + if (x < 9) map[x + 1] ^= (1 << y); + if (y > 0) map[x] ^= (1 << (y - 1)); + if (y < 9) map[x] ^= (1 << (y + 1)); + } +} +```