@@ -17,6 +17,7 @@ fn find_shortest_path(
1717 start : Point ,
1818 bodies_diff : & [ Point ] ,
1919 booster_map : & Matrix < Option < BoosterType > > ,
20+ drill_mode : bool ,
2021) -> Vec < Move > {
2122 let mut rng = thread_rng ( ) ;
2223 let mut moves = [
@@ -43,13 +44,18 @@ fn find_shortest_path(
4344 Some ( false ) => true ,
4445 _ => false ,
4546 } ) ;
47+
4648 let is_booster = match booster_map. get ( c) {
47- Some ( Some ( BoosterType :: NewHand ) ) => true ,
48- Some ( Some ( BoosterType :: Drill ) ) => true ,
49+ Some ( Some ( _) ) => true ,
4950 _ => false ,
5051 } ;
5152
52- if not_passed || is_booster {
53+ let is_valid = match valid. get ( c) {
54+ Some ( true ) => true ,
55+ _ => false ,
56+ } ;
57+
58+ if is_valid && ( not_passed || is_booster) {
5359 let mut res = Vec :: new ( ) ;
5460 let mut iter = c;
5561 while iter != start {
@@ -68,9 +74,12 @@ fn find_shortest_path(
6874 for m in & moves {
6975 let nc = c. move_with ( m) ;
7076 if let Some ( None ) = data. get ( nc) {
71- if let Some ( true ) = valid. get ( nc) {
72- data. set ( nc, Some ( ( m. clone ( ) , cost + 1 ) ) ) ;
73- queue. push_back ( nc) ;
77+ match ( valid. get ( nc) , drill_mode) {
78+ ( Some ( true ) , _) | ( Some ( false ) , true ) => {
79+ data. set ( nc, Some ( ( m. clone ( ) , cost + 1 ) ) ) ;
80+ queue. push_back ( nc) ;
81+ }
82+ _ => { }
7483 }
7584 }
7685 }
@@ -153,7 +162,6 @@ pub fn solve_small(task: Task) -> Vec<Command> {
153162
154163 let mut hand_count = 0 ;
155164 let mut drill_count = 0 ;
156- let mut drill_turns = 0 ;
157165
158166 while remaining > 0 {
159167 while hand_count > 0 && !new_bodies. is_empty ( ) {
@@ -162,10 +170,6 @@ pub fn solve_small(task: Task) -> Vec<Command> {
162170 bodies_diff. push ( new_hand) ;
163171 res. push ( Command :: NewHand ( new_hand) ) ;
164172 }
165- if drill_count > 0 && drill_turns == 0 {
166- drill_count -= 1 ;
167- drill_turns = 30 ;
168- }
169173 update_point (
170174 current_point,
171175 & bodies_diff,
@@ -183,7 +187,32 @@ pub fn solve_small(task: Task) -> Vec<Command> {
183187 current_point,
184188 & bodies_diff,
185189 & booster_map,
190+ false ,
186191 ) ;
192+ let moves = if drill_count > 0 {
193+ let drill_moves = find_shortest_path (
194+ width,
195+ height,
196+ & valid,
197+ & passed,
198+ current_point,
199+ & bodies_diff,
200+ & booster_map,
201+ true ,
202+ ) ;
203+ if drill_moves. len ( ) * 2 <= moves. len ( )
204+ && drill_moves. len ( ) >= 10
205+ && drill_moves. len ( ) < 30
206+ {
207+ drill_count -= 1 ;
208+ res. push ( Command :: Drill ) ;
209+ drill_moves
210+ } else {
211+ moves
212+ }
213+ } else {
214+ moves
215+ } ;
187216 for m in moves {
188217 current_point = current_point. move_with ( & m) ;
189218 update_point (
0 commit comments