luogu#P8174. [CEOI 2021] Stones

    ID: 7299 远端评测题 3000ms 512MiB 尝试: 0 已通过: 0 难度: 7 上传者: 标签>2021交互题Special JudgeCEOI(中欧)

[CEOI 2021] Stones

Background

Translated from CEOI 2021 Day 2 T1. Stones.

Problem Description

Ankica finally catches Branko, but he refuses to buy Ankica a newspaper and asks to come up with a new game because the previous one was unfair. Ankica pretends to be innocent and suggests another stone game, but Branko is suspicious and decides to completely change its rules.

The game has NN piles of stones. The ii-th pile contains aia_i stones. The players take turns removing some stones from one pile, and the player who takes the last stone wins.

However, in this game, which pile a player must take stones from is fixed by the other player.

More precisely, the turn number starts from 11 and increases by 11 each time, and the game proceeds as follows:

  • On odd-numbered turns, Branko specifies a non-empty pile. Ankica removes at least one stone and at most all stones from that pile.
  • On even-numbered turns, Ankica specifies a non-empty pile. Branko removes at least one stone and at most all stones from that pile.

As a professional game player, after Branko sets up the piles, Ankica quickly realizes that she has a winning strategy in this game.

If you are Ankica, can you win?

Interaction

This is an interactive problem. Your program must exchange information with the official program that plays Branko. Of course, your program should play the role of Ankica and ensure that she wins.

Your program should first read the initial state of the game from standard input. The initial state has two lines: the first line contains an integer NN, and the second line contains NN space-separated integers, where the ii-th one is aia_i, as described above.

Depending on whether the current turn is odd or even, your program should behave differently:

On odd turns:

  • Your program should first read an integer kk. If all piles are empty at this moment, then k=1k=-1, and you should terminate because you have lost. Otherwise, k[1,N]k\in[1,N], meaning you must remove stones from pile kk, at least one and at most all stones. It is guaranteed that pile kk is non-empty at this moment. Let pile kk currently contain sks_k stones.
  • Your program should output one integer in [1,sk][1,s_k], which is the number of stones you want to remove from pile kk, then flush the buffer.

On even turns:

  • Your program should first output an integer kk, then flush the buffer. If all piles are empty at this moment, then kk should be 1-1, and you should terminate because you have won. Otherwise, k[1,N]k\in[1,N], meaning you want Branko to remove stones from pile kk. You should ensure that pile kk is non-empty at this moment. Let pile kk currently contain sks_k stones.
  • Your program should read one integer in [1,sk][1,s_k], which is the number of stones Branko removes from pile kk.

It is guaranteed that the given initial state allows you to have a winning strategy no matter how Branko plays.

Interactive Sample 1

Output Input Explanation
1\texttt{1} There is only one pile.
4\texttt{4} This pile contains 44 stones.
1\texttt{1} Branko can only force Ankica to take from pile 11.
4\texttt{4} Ankica takes all stones from pile 11.
-1\texttt{-1} Now there are no stones left, Ankica wins.

Interactive Sample 2

Output Input Explanation
3\texttt{3} There are three piles.
1 1 5\texttt{1 1 5} The three piles contain 1,1,51,1,5 stones.
3\texttt{3} Branko forces Ankica to take from pile 33.
5\texttt{5} Ankica takes all stones from pile 33.
1\texttt{1} Ankica forces Branko to take from pile 11.
1\texttt{1} Branko can only take all stones from pile 11.
2\texttt{2} Branko forces Ankica to take from pile 22.
1\texttt{1} Ankica takes all stones from pile 22.
-1\texttt{-1} Now there are no stones left, Ankica wins.

Hint

Subtasks

Let M=max{a1,a2,,aN}M=\max\{a_1,a_2,\dots,a_N\}.

All test points satisfy 1N,M5001\leq N,M\leq 500.

The constraints for each subtask are as follows:

Subtask Score Constraints
11 1212 1N,M71\leq N,M\leq 7
22 1313 1N121\leq N\leq 12, 1M5001\leq M\leq 500
33 1515 1N,M5001\leq N,M\leq 500, and i,j[1,N],ai=aj\forall i,j\in[1,N],a_i=a_j
44 6060 1N,M5001\leq N,M\leq 500

Translated by ChatGPT 5