From c9aadc854a8dd456336da52bb3d898d3cee0e983 Mon Sep 17 00:00:00 2001 From: suyeun84 <81475092+suyeun84@users.noreply.github.com> Date: Tue, 21 Oct 2025 17:45:18 +0900 Subject: [PATCH] =?UTF-8?q?[20251021]=20BOJ=20/=20G2=20/=20=EB=A7=88?= =?UTF-8?q?=ED=94=BC=EC=95=84=20/=20=EA=B9=80=EC=88=98=EC=97=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...2 \353\247\210\355\224\274\354\225\204.md" | 72 +++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100644 "suyeun84/202510/21 BOJ G2 \353\247\210\355\224\274\354\225\204.md" diff --git "a/suyeun84/202510/21 BOJ G2 \353\247\210\355\224\274\354\225\204.md" "b/suyeun84/202510/21 BOJ G2 \353\247\210\355\224\274\354\225\204.md" new file mode 100644 index 00000000..8b053d0e --- /dev/null +++ "b/suyeun84/202510/21 BOJ G2 \353\247\210\355\224\274\354\225\204.md" @@ -0,0 +1,72 @@ +```java +import java.io.*; +import java.util.*; + +public class boj1079 { + static BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + static StringTokenizer st; + static void nextLine() throws Exception { st = new StringTokenizer(br.readLine()); } + static int nextInt() { return Integer.parseInt(st.nextToken()); } + + static boolean[] isDead; + static int N, mafia, answer = 0; + static int[][] R; + static int[] guilty; + public static void main(String[] args) throws Exception { + nextLine(); + N = nextInt(); + isDead = new boolean[N]; + guilty = new int[N]; + mafia = -1; + R = new int[N][N]; + nextLine(); + for (int i = 0; i < N; i++) guilty[i] = nextInt(); + for (int i = 0; i < N; i++) { + nextLine(); + for (int j = 0; j < N; j++) { + R[i][j] = nextInt(); + } + } + nextLine(); + mafia = nextInt(); + dfs(N, 0); + + System.out.println(answer); + } + + static void dfs(int alive, int nights) { + if (isDead[mafia] || alive == 1) { + answer = Math.max(answer, nights); + return; + } + if (alive % 2 == 0) { // 밤 + for (int i = 0; i < N; i++) { + if (isDead[i] || i == mafia) continue; + isDead[i] = true; + changeGuilty(1, i); + dfs(alive-1, nights+1); + changeGuilty(-1, i); + isDead[i] = false; + } + } else { // 낮 + int maxGuilty = Integer.MIN_VALUE; + int idx = -1; + for (int i = 0; i < N; i++) { + if (isDead[i] || guilty[i] <= maxGuilty) continue; + maxGuilty = guilty[i]; + idx = i; + } + isDead[idx] = true; + dfs(alive-1, nights); + isDead[idx] = false; + } + } + + static void changeGuilty(int type, int idx) { + for (int i = 0; i < N; i++) { + if (isDead[i]) continue; + guilty[i] += type * R[idx][i]; + } + } + } +```