Skip to content

Commit e171d51

Browse files
authored
[20250930] BOJ / G4 / 뮤탈리스크 / 김수연
[20250930] BOJ / G4 / 뮤탈리스크 / 김수연
2 parents 5cc004d + e99ea30 commit e171d51

File tree

1 file changed

+57
-0
lines changed

1 file changed

+57
-0
lines changed
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
```java
2+
import java.io.*;
3+
import java.util.*;
4+
5+
public class boj12869 {
6+
static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
7+
static StringTokenizer st;
8+
static void nextLine() throws Exception { st = new StringTokenizer(br.readLine()); }
9+
static int nextInt() { return Integer.parseInt(st.nextToken()); }
10+
11+
public static void main(String[] args) throws Exception {
12+
nextLine();
13+
int N = nextInt();
14+
15+
int[] hp = new int[3];
16+
Arrays.fill(hp, 0);
17+
18+
nextLine();
19+
for (int i = 0; i < N; i++) hp[i] = nextInt();
20+
21+
boolean[][][] visited = new boolean[61][61][61];
22+
Queue<int[]> q = new ArrayDeque<>();
23+
q.offer(new int[]{hp[0], hp[1], hp[2]});
24+
visited[hp[0]][hp[1]][hp[2]] = true;
25+
26+
int[][] dmg = {
27+
{9,3,1},{9,1,3},
28+
{3,9,1},{3,1,9},
29+
{1,9,3},{1,3,9}
30+
};
31+
32+
int attacks = 0;
33+
while (!q.isEmpty()) {
34+
int sz = q.size();
35+
for (int s = 0; s < sz; s++) {
36+
int[] cur = q.poll();
37+
int a = cur[0], b = cur[1], c = cur[2];
38+
if (a == 0 && b == 0 && c == 0) {
39+
System.out.println(attacks);
40+
return;
41+
}
42+
for (int[] d : dmg) {
43+
int na = Math.max(0, a - d[0]);
44+
int nb = Math.max(0, b - d[1]);
45+
int nc = Math.max(0, c - d[2]);
46+
if (!visited[na][nb][nc]) {
47+
visited[na][nb][nc] = true;
48+
q.offer(new int[]{na, nb, nc});
49+
}
50+
}
51+
}
52+
attacks++;
53+
}
54+
System.out.println(attacks);
55+
}
56+
}
57+
```

0 commit comments

Comments
 (0)