From c00feecbc9f2c55f6ee749c9e136bbe9175493e2 Mon Sep 17 00:00:00 2001 From: JHLEE325 <82587652+JHLEE325@users.noreply.github.com> Date: Mon, 2 Mar 2026 20:58:08 +0900 Subject: [PATCH] =?UTF-8?q?[20260302]=20BOJ=20/=20G5=20/=20=EB=A7=81?= =?UTF-8?q?=ED=81=AC=EC=99=80=20=EC=8A=A4=ED=83=80=ED=8A=B8=20/=20?= =?UTF-8?q?=EC=9D=B4=EC=A4=80=ED=9D=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...0 \354\212\244\355\203\200\355\212\270.md" | 69 +++++++++++++++++++ 1 file changed, 69 insertions(+) create mode 100644 "JHLEE325/202603/02 BOJ G5 \353\247\201\355\201\254\354\231\200 \354\212\244\355\203\200\355\212\270.md" diff --git "a/JHLEE325/202603/02 BOJ G5 \353\247\201\355\201\254\354\231\200 \354\212\244\355\203\200\355\212\270.md" "b/JHLEE325/202603/02 BOJ G5 \353\247\201\355\201\254\354\231\200 \354\212\244\355\203\200\355\212\270.md" new file mode 100644 index 00000000..858165a4 --- /dev/null +++ "b/JHLEE325/202603/02 BOJ G5 \353\247\201\355\201\254\354\231\200 \354\212\244\355\203\200\355\212\270.md" @@ -0,0 +1,69 @@ +```java +import java.io.*; +import java.util.*; + +public class Main { + + static int N; + static int[][] S; + static boolean[] startTeam; + static int minDiff = Integer.MAX_VALUE; + + public static void main(String[] args) throws IOException { + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + StringTokenizer st; + N = Integer.parseInt(br.readLine()); + S = new int[N][N]; + + for (int i = 0; i < N; i++) { + st = new StringTokenizer(br.readLine()); + for (int j = 0; j < N; j++) { + S[i][j] = Integer.parseInt(st.nextToken()); + } + } + + startTeam = new boolean[N]; + + divide(0); + + System.out.println(minDiff); + } + + static void divide(int idx) { + if (idx == N) { + calculate(); + return; + } + + startTeam[idx] = true; + divide(idx + 1); + + startTeam[idx] = false; + divide(idx + 1); + } + + static void calculate() { + int startSum = 0; + int linkSum = 0; + + for (int i = 0; i < N; i++) { + for (int j = i + 1; j < N; j++) { + if (startTeam[i] && startTeam[j]) { + startSum += S[i][j] + S[j][i]; + } else if (!startTeam[i] && !startTeam[j]) { + linkSum += S[i][j] + S[j][i]; + } + } + } + + int diff = Math.abs(startSum - linkSum); + + if (diff == 0) { + System.out.println(0); + System.exit(0); + } + + minDiff = Math.min(minDiff, diff); + } +} +```