BOXGAM97 (Help)

Hello everyone , can anyone tell me why my first got AC and other one got WA , give some test case to fail.
Question : CodeChef: Practical coding for everyone

Answers:

  1. CodeChef: Practical coding for everyone
  2. CodeChef: Practical coding for everyone

PS: Read my solution from line 370 :slight_smile:
@l_returns @aryanc403 @anon55659401 @kshitij_789

2 Likes

The test case is:
3
7 4 1
2 4 3 2 3 4 1
6 4 1
1 3 1 1 2 1
6 4 0
1 3 1 1 2 1

Expected output:
3
1
3

Your output:
4
2
1

please explain this output

The array is 2 4 3 2 3 4 1
Anil puts the bal at a[1]=4…then jafar moves it to a[2]=3 then again Anil again moves the ball to a[1]=4 then finally Jafar moves the ball to a[2]=3 thus ending the moves to get the ball at a[2]=3

@ssrivastava990 , I also try to solve problem by second solution and got WA. I thought it from one another way that what if there are repeated max/min elements then the current player will try to choose one that how max/min elements around this item but it also failed.

Can you explain, your first solution? Why you are finding max(maxi, min(a[i-1], a[i+1]))?

i am getting this right in my code still i got a WA, can you kindly verify whats the test case i am missing
https://www.codechef.com/viewsolution/27588613

This situation arises when the first one to play wants to minimise (Almir) but is losing which means that k is even. You can interpret this like, we take min(a[i-1], a[i+1]) which Almir wants, but we take maximum because Jafar wants the maximum possible result. a[i-1] and a[i+1] is taken because the next player to play can shift the box in these 2 places only.

1 Like

it is said in the quotes
"Jafar plays in such a way that when the game ends, the number on the box which contains the ball is the biggest possible. On the contrary, Almir wants this number to be the smallest possible. "
As it is almir turn first and he knows that last turn won’t be his
so he prefer choosing element a[1]=4 over element a[6]=1
as he knows it will output number which is less than left element of a[6]=1

Can you look at my code it giving correct output but still fails
Used a window size to find maximum /minimum in it and then get global maxima or minima
https://www.codechef.com/viewsolution/27591829

Doubt: In statement it is written that a player can move to left or right which implies that it may move left or right or not move at all, is this correct?

“In each turn, the current player can move the ball one box to the left (unless it is in box 11) or one box to the right (unless it is in box NN).” - But here it is not mentioned that a player should move the ball by means of mandatory. By your explanation when it comes jafer he can simply pass his turn without moving the ball in order to get the maximum number possible. Because it is also mentioned that “assuming that both players play optimally.” which confirms my argument.

“By your explanation when it comes jafar he can simply pass his turn without moving the ball in order to get the maximum number possible”
when did i explain it,
both the player have to make a move,skipping is not an option
i just explained as k is even , and its almir turn first he prefer choosing a[1]=4 over a[6]=1
because the output will be less,i.e,a[2]=3(output) which is less than output a[5]=4