From cbfcbd31e4eeb6848cd7d35ea63f020db6668798 Mon Sep 17 00:00:00 2001 From: zinnnn37 Date: Thu, 20 Nov 2025 20:24:00 +0900 Subject: [PATCH] =?UTF-8?q?[20251120]=20BOJ=20/=20G4=20/=20=EB=AC=BC?= =?UTF-8?q?=ED=86=B5=20/=20=EA=B9=80=EB=AF=BC=EC=A7=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../20 BJ G4 \353\254\274\355\206\265.md" | 90 +++++++++++++++++++ 1 file changed, 90 insertions(+) create mode 100644 "zinnnn37/202511/20 BJ G4 \353\254\274\355\206\265.md" diff --git "a/zinnnn37/202511/20 BJ G4 \353\254\274\355\206\265.md" "b/zinnnn37/202511/20 BJ G4 \353\254\274\355\206\265.md" new file mode 100644 index 00000000..288c4167 --- /dev/null +++ "b/zinnnn37/202511/20 BJ G4 \353\254\274\355\206\265.md" @@ -0,0 +1,90 @@ +```java +import java.io.*; +import java.util.Set; +import java.util.StringTokenizer; +import java.util.TreeSet; + +public class BJ_2251_물통 { + + private static final BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + private static final BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out)); + private static final StringBuilder sb = new StringBuilder(); + private static StringTokenizer st; + + private static int[] capacity; + private static Set candidate; + private static boolean[][] visited; + + public static void main(String[] args) throws IOException { + init(); + sol(); + } + + private static void init() throws IOException { + st = new StringTokenizer(br.readLine()); + + capacity = new int[3]; + for (int i = 0; i < 3; i++) { + capacity[i] = Integer.parseInt(st.nextToken()); + } + visited = new boolean[capacity[0] + 1][capacity[1] + 1]; + candidate = new TreeSet<>(); + } + + private static void sol() throws IOException { + dfs(0, 0, capacity[2]); + + for (int c : candidate) { + bw.write(c + " "); + } + bw.flush(); + bw.close(); + br.close(); + } + + private static void dfs(int a, int b, int c) throws IOException { + if (visited[a][b]) return; + + // a가 0일 때 c에 담긴 물의 양 + if (a == 0) candidate.add(c); + + visited[a][b] = true; + + // a -> b + if (a + b <= capacity[1]) { + dfs(0, a + b, c); + } else { + dfs(a + b - capacity[1], capacity[1], c); + } + + // b -> a + if (a + b <= capacity[0]) { + dfs(a + b, 0, c); + } else { + dfs(capacity[0], a + b - capacity[0], c); + } + + // b -> c + if (b + c <= capacity[2]) { + dfs(a, 0, b + c); + } else { + dfs(a, b + c - capacity[2], capacity[2]); + } + + // c -> a + if (a + c <= capacity[0]) { + dfs(a + c, b, 0); + } else { + dfs(capacity[0], b, a + c - capacity[0]); + } + + // c -> b + if (b + c <= capacity[1]) { + dfs(a, b + c, 0); + } else { + dfs(a, capacity[1], b + c - capacity[1]); + } + } + +} +``` \ No newline at end of file