Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 52 additions & 0 deletions suyeun84/202506/29 BOJ G4 물통
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
```java
import java.io.*;
import java.util.*;

public class boj2251 {
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 int A, B, C;
static Set<Integer> answer;
static boolean[][][] visited;
static int[] capacity;
public static void main(String[] args) throws Exception {
nextLine();
A = nextInt();
B = nextInt();
C = nextInt();
answer = new TreeSet<>();
capacity = new int[]{A, B, C};
visited = new boolean[A + 1][B + 1][C + 1];

dfs(0, 0, C);

for (int a : answer) System.out.print(a + " ");
}
static void dfs(int a, int b, int c) {
if (visited[a][b][c]) return;

visited[a][b][c] = true;

if (a == 0) answer.add(c);

for (int i = 0; i < 3; i++) {
for (int j = 0; j < 3; j++) {
if (i != j) {
int[] next = pour(new int[]{a, b, c}, i, j);
dfs(next[0], next[1], next[2]);
}
}
}
}
static int[] pour(int[] state, int from, int to) {
int[] next = state.clone();
int amount = Math.min(state[from], capacity[to] - state[to]);
next[from] -= amount;
next[to] += amount;
return next;
}
}
```