[Solution] Chef & Cook Game solution codechef

Chef & Cook Game solution codechef – There is a non-negative integer array A of length N. Chef and Cook will play a game on the array with Chef starting first.

Table of Contents

[Solution] Chef & Cook Game solution codechef

In one turn the player will perform the following operation:

  • Choose two indices i,j such that 1 \leq i \lt j \leq N and A_i \gt 0.
  • Set A_i \gets A_i – 1 and A_j \gets A_j + 1, i.e, subtract 1 from A_i and add 1 to A_j.

The player who is unable to perform the operation loses. If both Chef and Cook play optimally, who will win?

Input Format

  • The first line of input will contain a single integer T, denoting the number of test cases.
    • The first line of each test case contains a single integer N denoting the length of the array.
    • The second line of teach test case contains N integers A_1,A_2,\ldots,A_N denoting the initial values of the array.

Output Format

For each test case, output “Chef” if Chef wins, otherwise output “Cook” (without quotes).

Each letter of the output may be printed in either uppercase or lowercase. For example, ChefchEfCHEF, and cHEf will all be treated as equivalent.

[Solution] Chef & Cook Game solution codechef

  • 1 \leq T \leq 1000
  • 1 \leq N \leq 100
  • 0 \leq A_i \leq 10^9
  • There are no limits on the sum of N over all test cases.

Sample 1:



1 0 1 0
1 2 3 4

Chef & Cook Game solution codechef Explanation:

For the first test case, Chef wins. Here is the strategy for Chef.

  • Initially, A = [1, 0, 1, 0].
  • In the first turn, Chef will pick i=1 and j=3. Then, A = [0,0,2,0].
  • In the second turn, Cook is can only pick i=3 and j=4. Then A=[0,0,1,1].
  • In the third turn, Chef will pick i=3 and j=4. Then A=[0,0,0,2].
  • In the fourth turn, Cook cannot perform any operation and loses. Therefore, Chef has won.

For Solution

“Click Here”

Leave a Comment