DMOPC '21 Contest 1 P1 - Partial Game

View as PDF

Submit solution


Points: 5 (partial)
Time limit: 2.0s
Memory limit: 256M

Author:
Problem type

The Duke of Death suffers from the horrible condition of killing anything that he touches. Thus, to pass time, he likes to play games involving inanimate objects with his maid Alice. One such game involves N piles of stones, with A_i stones in the i-th pile. The Duke and Alice take turns making moves, with the Duke going first:

On the Duke's turn, if there is at least one non-empty pile with an even number of stones, then he should choose one of those piles and remove any positive number of stones from that pile. Otherwise, he does nothing and passes the turn to Alice.

Similarly, on Alice's turn, if there is at least one non-empty pile with an odd number of stones, then she should choose one of those piles and remove any positive number of stones from that pile. Otherwise, she does nothing and passes the turn to the Duke.

The game ends when there are no stones left in any pile, and the player who took the last stone is declared the winner. If both players play optimally, who has a winning strategy? A player has a winning strategy if they can guarantee their win regardless of what their opponent chooses to do. In this game, we can prove that one of the players always has a winning strategy.

Constraints

1 \le N \le 2 \times 10^5

1 \le A_i \le 10^9

Subtask 1 [20%]

1 \le A_i \le 2

Subtask 2 [80%]

No additional constraints.

Input Specification

The first line contains an integer N, the number of piles.

The next line contains N integers A_i (1 \le i \le N), the number of stones in each pile.

Output Specification

Output Duke if the Duke has a winning strategy, or Alice if Alice has a winning strategy.

Sample Input 1

4
2 1 2 2

Sample Output 1

Duke

Explanation for Sample 1

For example, one instance of a game could go as follows:

  1. The Duke takes 1 stone from pile 1, changing the number of stones in each pile to [1, 1, 2, 2].
  2. Alice takes 1 stone from pile 2, changing the number of stones in each pile to [1, 0, 2, 2].
  3. The Duke takes 2 stones from pile 4, changing the number of stones in each pile to [1, 0, 2, 0].
  4. Alice takes 1 stone from pile 1, changing the number of stones in each pile to [0, 0, 2, 0].
  5. The Duke takes 2 stones from pile 3, changing the number of stones in each pile to [0, 0, 0, 0].

In this case, the Duke took the last stone, so he is the winner. In general, we can prove that the Duke has a winning strategy here, so we output Duke.

Sample Input 2

3
1 4 1

Sample Output 2

Alice

Explanation for Sample 2

As another example, the game could proceed as follows:

  1. The Duke takes 1 stone from pile 2, changing the number of stones in each pile to [1, 3, 1].
  2. Alice takes 1 stone from pile 2, changing the number of stones in each pile to [1, 2, 1].
  3. The Duke takes 2 stones from pile 2, changing the number of stones in each pile to [1, 0, 1].
  4. Alice takes 1 stone from pile 3, changing the number of stones in each pile to [1, 0, 0].
  5. The Duke passes the turn to Alice.
  6. Alice takes 1 stone from pile 1, changing the number of stones in each pile to [0, 0, 0].

In this case, Alice took the last stone, so she is the winner. In general, we can prove that Alice has a winning strategy here, so we output Alice.


Comments


  • 2
    MarsFlat  commented on Sept. 10, 2021, 11:37 p.m.

    If you require assistance on this problem, it happens to have an editorial readily available if you are stuck.

    It's also recommended to join the slack or discord for further assistance as wait times are often less and it does not clog the comments section.


  • 0
    William_Tian1  commented on Sept. 10, 2021, 10:20 a.m.

    you might have to use long for the second part


    • 0
      dchoo333  commented on Sept. 10, 2021, 7:38 p.m.

      What do you mean? I’m trying to solve this so it could be helpful.


      • 1
        Nils_Emmenegger  commented on Sept. 10, 2021, 8:26 p.m. edited

        They are referring to using 64-bit integers instead of 32-bit integers to prevent integer overflow. This isn't a concern if you are using a language that handles this automatically like Python or JavaScript, but it does matter for (among many others) Java and C++.


        • 0
          dchoo333  commented on Sept. 10, 2021, 9:00 p.m.

          What is wrong with my Batch #2 Case #2?