/
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 700 点
問題文
この問題は インタラクティブな問題 (あなたの作成したプログラムとジャッジシステムが入出力を介して対話を行う形式の問題) です.
1 から N までの番号が付けられた N 個の山があります.また,それぞれの山には石が N - 1 個ずつあります.
これらを用いて先手と後手でゲームを行うことを考えます.ゲームでは先手から交互に手番を行います.
- 先手は石が 1 つ以上存在する山を 1 個選ぶ.そこから 1 個以上 K 個以下の石を取り除く.
- 後手は石が 1 つ以上存在する山を 1 個以上 K 個以下選ぶ.それらから石を 1 個ずつ取り除く.
先に操作ができなくなった方の負けです.あなたはこのゲームをジャッジと対戦します.まず,ジャッジにあなたが先手となるか後手となるかを宣言し,その後ゲームを行ってください.
制約
- 2 \leq N \leq 200
- 1 \leq K \leq N
- 入力される値はすべて整数である
入出力
この問題はインタラクティブな問題 (あなたの作成したプログラムとジャッジシステムが入出力を介して対話を行う形式の問題) です.
最初に,N, K が以下の形式で与えられるので標準入力から受け取ってください.
N K
先手として対戦する場合
- まず
Firstを出力して改行してください. - 次に,ゲームが終了するまで以下のやり取りを繰り返してください.
- まず,あなたが取る先手の行動を出力してください.山 i から石を j 個取り除く場合,i, j をこの順に空白区切りで出力して改行してください.
- 次に,ジャッジが取る後手の行動を受け取ってください.まず,整数 k を受け取ってください.意味は以下の通りです.
- k = -1: あなたがこの問題で不正解と判定されたことを示します.ただちにプログラムを終了してください.
- k = 0: あなたがこの問題で正解と判定されたことを示します.ただちにプログラムを終了してください.
- k > 0: 続いて,k 個の整数 a_1, a_2, \cdots, a_k が空白区切りで与えられます.これは,後手が山 a_1, a_2, \cdots, a_k から 1 個ずつ石を取り除くことを示します.
後手として対戦する場合
- まず
Secondを出力して改行してください. - 次に,ゲームが終了するまで以下のやり取りを繰り返してください.
- まず,ジャッジが取る先手の行動を受け取ってください.2 つの整数 i, j を受け取ってください.意味は以下の通りです.
- i = -1: このとき,j = -1 です.あなたがこの問題で不正解と判定されたことを示します.ただちにプログラムを終了してください.
- i = 0: このとき,j = 0 です.あなたがこの問題で正解と判定されたことを示します.ただちにプログラムを終了してください.
- i > 0: これは,先手が山 i から j 個の石を取り除いたことを示します.
- 次に,あなたが取る後手の行動を出力してください.山 a_1, a_2, \cdots, a_k から 1 個ずつ石を取り除く場合,まず k を出力して改行してください.その後,a_1, a_2, \cdots, a_k を空白区切りで出力して改行してください.
- まず,ジャッジが取る先手の行動を受け取ってください.2 つの整数 i, j を受け取ってください.意味は以下の通りです.
注意点
- 出力を行うたびに,末尾に改行を入れて標準出力を flush してください.そうしなかった場合,ジャッジ結果が TLE となる可能性があります.
- あなたがゲームで勝利した場合,正解と判定されます.
- あなたがゲームで負けた場合,もしくは不正な出力を行なった場合,不正解と判定されます.
- あなたがこの問題で正解もしくは不正解と判定されたことをジャッジから受け取ったら,ただちにプログラムを終了してください.そうしない場合,ジャッジ結果は不定です.
- 余計な改行は不正なフォーマットの出力とみなされることに注意してください.
入出力例
入出力例 1
N = 3, K = 2 として先手として対戦するときのやり取りの一例を示します.
| 入力 | 出力 | 説明 |
|---|---|---|
3 2 |
まず整数 N, K が与えられます. | |
First |
先手として対戦することをジャッジに出力します. | |
3 1 |
山 3 から石を 1 個取り除きます. | |
2 |
ジャッジは山 1, 3 から石を 1 個ずつ取り除きます. | |
1 1 |
山 1 から石を 1 個取り除きます. | |
1 |
ジャッジは山 2 から石を 1 個取り除きます. | |
2 1 |
山 2 から石を 1 個取り除きます. | |
0 |
ジャッジは操作ができなくなったので負けとなったため,あなたがゲームで勝利し正解と判定されたことを示します. |
入出力例 2
N = 2, K = 1 として後手として対戦するときのやり取りの一例を示します.
| 入力 | 出力 | 説明 |
|---|---|---|
2 1 |
まず整数 N, K が与えられます. | |
Second |
後手として対戦することをジャッジに出力します. | |
1 1 |
ジャッジは山 1 から石を 1 個取り除きます. | |
1 |
山 2 から石を 1 個取り除きます. | |
0 0 |
ジャッジは操作ができなくなったので負けとなったため,あなたがゲームで勝利し正解と判定されたことを示します. |
これらはやり取りの一例であり,実際のジャッジがこのように動作することを保証するわけではありません.
Score : 700 points
Problem Statement
This is an interactive problem (where your program interacts with the judge system via Standard Input and Output).
There are N piles numbered from 1 to N. Each pile has N - 1 stones.
Consider a game played by the first player and the second player using these. In the game, the players take turns alternately, starting with the first player.
- The first player chooses one pile that has one or more stones, and removes between 1 and K stones, inclusive, from it.
- The second player chooses between 1 and K piles, inclusive, each of which has one or more stones, and removes one stone from each of them.
The player who first becomes unable to make a move loses. You will play this game against the judge. First, declare to the judge whether you will be the first player or the second player, and then play the game.
Constraints
- 2 \leq N \leq 200
- 1 \leq K \leq N
- All input values are integers.
Input and Output
This is an interactive problem (where your program interacts with the judge system via Standard Input and Output).
First, N and K are given in the following format; receive them from Standard Input.
N K
When playing as the first player
- First, output
Firstfollowed by a newline. - Then, repeat the following interaction until the game ends.
- First, output your move as the first player. If you remove j stones from pile i, output i and j in this order, separated by a space, followed by a newline.
- Next, receive the judge's move as the second player. First, receive an integer k. It means the following.
- k = -1: This indicates that you have been judged as incorrect for this problem. Terminate your program immediately.
- k = 0: This indicates that you have been judged as correct for this problem. Terminate your program immediately.
- k > 0: Subsequently, k integers a_1, a_2, \cdots, a_k are given, separated by spaces. This indicates that the second player removes one stone from each of piles a_1, a_2, \cdots, a_k.
When playing as the second player
- First, output
Secondfollowed by a newline. - Then, repeat the following interaction until the game ends.
- First, receive the judge's move as the first player. Receive two integers i and j. They mean the following.
- i = -1: In this case, j = -1. This indicates that you have been judged as incorrect for this problem. Terminate your program immediately.
- i = 0: In this case, j = 0. This indicates that you have been judged as correct for this problem. Terminate your program immediately.
- i > 0: This indicates that the first player removed j stones from pile i.
- Next, output your move as the second player. If you remove one stone from each of piles a_1, a_2, \cdots, a_k, first output k followed by a newline. Then, output a_1, a_2, \cdots, a_k, separated by spaces, followed by a newline.
- First, receive the judge's move as the first player. Receive two integers i and j. They mean the following.
Notes
- For each output, add a newline at the end and flush Standard Output. Otherwise, you may receive a TLE verdict.
- If you win the game, you will be judged as correct.
- If you lose the game, or if you make a malformed output, you will be judged as incorrect.
- Once you receive from the judge that you have been judged correct or incorrect for this problem, terminate your program immediately. Otherwise, the verdict is indeterminate.
- Note that extra newlines are considered as a malformed output.
Sample Interaction
Sample Interaction 1
The following is an example of the interaction when N = 3, K = 2 and you play as the first player.
| Input | Output | Explanation |
|---|---|---|
3 2 |
First, the integers N, K are given. | |
First |
Output to the judge that you will play as the first player. | |
3 1 |
Remove one stone from pile 3. | |
2 |
The judge removes one stone from each of piles 1, 3. | |
1 1 |
Remove one stone from pile 1. | |
1 |
The judge removes one stone from pile 2. | |
2 1 |
Remove one stone from pile 2. | |
0 |
The judge has lost because it became unable to make a move, which indicates that you won the game and have been judged as correct. |
Sample Interaction 2
The following is an example of the interaction when N = 2, K = 1 and you play as the second player.
| Input | Output | Explanation |
|---|---|---|
2 1 |
First, the integers N, K are given. | |
Second |
Output to the judge that you will play as the second player. | |
1 1 |
The judge removes one stone from pile 1. | |
1 |
Remove one stone from pile 2. | |
0 0 |
The judge has lost because it became unable to make a move, which indicates that you won the game and have been judged as correct. |
These are merely examples of the interaction, and it is not guaranteed that the actual judge behaves in this way.