CF1839E.Decreasing Game

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

This is an interactive problem.

Consider the following game for two players:

  • Initially, an array of integers a1,a2,,ana_1, a_2, \ldots, a_n of length nn is written on blackboard.
  • Game consists of rounds. On each round, the following happens:
    • The first player selects any ii such that ai>0a_i \gt 0 . If there is no such ii , the first player loses the game (the second player wins) and game ends.
    • The second player selects any jij \neq i such that aj>0a_j \gt 0 . If there is no such jj , the second player loses the game (the first player wins) and game ends.
    • Let d=min(ai,aj)d = \min(a_i, a_j) . The values of aia_i and aja_j are simultaneously decreased by dd and the next round starts.

It can be shown that game always ends after the finite number of rounds.

You have to select which player you will play for (first or second) and win the game.

输入格式

The first line contains a single integer nn ( 1n3001 \le n \le 300 ) — the length of array aa .

The second line contains nn integers a1,a2,,ana_1, a_2, \ldots, a_n ( 1ai3001 \le a_i \le 300 ) — array aa .

输出格式

Interaction begins after reading nn and array aa .

You should start interaction by printing a single line, containing either "First" or "Second", representing the player you select.

On each round, the following happens:

  • If you are playing as the first player, you should print a single integer ii ( 1in1 \le i \le n ) on a separate line. After that, you should read a single integer jj ( 1jn-1 \le j \le n ) written on a separate line.If j=1j = -1 , then you made an incorrect move. In this case your program should terminate immediately.

    If j=0j = 0 , then the second player can't make a correct move and you win the game. In this case your program should also terminate immediately.

    Otherwise jj is equal to the index chosen by the second player, and you should proceed to the next round.

  • If you are playing as the second player, you should read a single integer ii ( 1in-1 \le i \le n ) written on a separate line.If i=1i = -1 , then you made an incorrect move on the previous round (this cannot happen on the first round). In that case your program should terminate immediately.

    If i=0i = 0 , then the first player can't make a correct move and you win the game. In this case your program should also terminate immediately.

    Otherwise ii is equal to the index chosen by first player. In this case you should write single integer jj ( 1jn1 \le j \le n ) on a separate line and proceed to the next round.

After printing ii or jj , do not forget to output the end of line and flush the output. Otherwise, you will get Idleness limit exceeded. To do this, use:

  • fflush(stdout) or cout.flush() in C++;
  • System.out.flush() in Java;
  • flush(output) in Pascal;
  • stdout.flush() in Python;
  • see the documentation for other languages.

Hacks

Hacks are disabled in this problem.

输入输出样例

  • 输入#1

    4
    10 4 6 3
    
    
    3
    
    1
    
    0

    输出#1

    First
    1
    
    2
    
    4
  • 输入#2

    6
    4 5 5 11 3 2
    
    2
    
    5
    
    4
    
    6
    
    1
    
    0

    输出#2

    Second 
    
    4
    
    4
    
    3
    
    1
    
    3

说明/提示

In the first example n=4n = 4 and array aa is [10,4,6,3][\, 10, 4, 6, 3 \,] . The game goes as follows:

  • After reading array aa contestant's program chooses to play as the first player and prints "First".
  • First round: the first player chooses i=1i = 1 , the second player chooses j=3j = 3 . d=min(a1,a3)=min(10,6)=6d = \min(a_1, a_3) = \min(10, 6) = 6 is calculated. Elements a1a_1 and a3a_3 are decreased by 66 . Array aa becomes equal to [4,4,0,3][\, 4, 4, 0, 3 \,] .
  • Second round: the first player chooses i=2i = 2 , the second player chooses j=1j = 1 . d=min(a2,a1)=min(4,4)=4d = \min(a_2, a_1) = \min(4, 4) = 4 is calculated. Elements a2a_2 and a1a_1 are decreased by 44 . Array aa becomes equal to [0,0,0,3][\, 0, 0, 0, 3 \,] .
  • Third round: the first player chooses i=4i = 4 . There is no j4j \neq 4 such that aj>0a_j > 0 , so the second player can't make a correct move and the first player wins. Jury's program prints j=0j = 0 . After reading it, contestant's program terminates.

In the second example n=6n = 6 and array aa is [4,5,5,11,3,2][\, 4, 5, 5, 11, 3, 2 \,] . The game goes as follows:

  • Contestant's program chooses to play as the second player and prints "Second".
  • First round: i=2i = 2 , j=4j = 4 , a=[4,0,5,6,3,2]a = [\, 4, 0, 5, 6, 3, 2 \,] .
  • Second round: i=5i = 5 , j=4j = 4 , a=[4,0,5,3,0,2]a = [\, 4, 0, 5, 3, 0, 2 \,] .
  • Third round: i=4i = 4 , j=3j = 3 , a=[4,0,2,0,0,2]a = [\, 4, 0, 2, 0, 0, 2 \,] .
  • Fourth round: i=6i = 6 , j=1j = 1 , a=[2,0,2,0,0,0]a = [\, 2, 0, 2, 0, 0, 0 \,] .
  • Fifth round: i=1i = 1 , j=3j = 3 , a=[0,0,0,0,0,0]a = [\, 0, 0, 0, 0, 0, 0 \,] .
  • Sixth round: the first player can't make a correct move and the second player wins. Jury's program prints i=0i = 0 . After reading it, contestant's program terminates.

Note that the example interaction contains extra empty lines so that it's easier to read. The real interaction doesn't contain any empty lines and you shouldn't print any extra empty lines as well.

首页