File tree Expand file tree Collapse file tree 1 file changed +57
-0
lines changed
Expand file tree Collapse file tree 1 file changed +57
-0
lines changed Original file line number Diff line number Diff line change 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+ ```
You can’t perform that action at this time.
0 commit comments