AT_arc219_d.Grid Game
提高+/省选-
通过率:0%
时间限制:2.00s
内存限制:1024MB
AC君温馨提醒
该题目为【atcoder】题库的题目,您提交的代码将被提交至atcoder进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
There is an N×N grid. The cell at the i-th row from the top and the j-th column from the left is denoted as cell (i,j). Cell (i,j) initially contains Ai,j stones.
Alice and Bob play the following game using this grid.
- Starting with Alice, the two players alternate taking turns.
- On each turn, the player chooses a cell and moves at least 1 and at most K stones from it together to an adjacent cell above or to the left. Specifically, the following steps are performed in order:
- Choose a cell (i,j) that contains at least 1 stone. Cell (1,1) cannot be chosen.
- Let c be the number of stones in cell (i,j), and choose an integer x satisfying 1≤x≤min(c,K).
- Choose as the destination either cell (i−1,j) (if it exists) or cell (i,j−1) (if it exists), then remove x stones from cell (i,j) and move all of them to that cell.
The player who cannot take a turn first loses.
Determine which player wins when both play optimally.
You are given T test cases; solve each of them.
有一个 N×N 的网格。从上往下第 i 行、从左往右第 j 列的格子记为格子 (i,j)。格子 (i,j) 初始时包含 Ai,j 颗石子。
Alice 和 Bob 使用该网格进行如下游戏:
- Alice 先手,两人轮流进行操作。
- 每一轮中,当前玩家选择一个格子,并从中向正上方或正左方的相邻格子一次性移动至少 1 颗、至多 K 颗石子。具体操作步骤按顺序如下:
- 选择一个至少含 1 颗石子的格子 (i,j);但格子 (1,1) 不可被选中。
- 设格子 (i,j) 中当前石子数为 c,选择一个整数 x,满足 1≤x≤min(c,K)。
- 将 x 颗石子从格子 (i,j) 中移除,并全部移入目标格子:若目标为 (i−1,j)(要求该格子存在),或 (i,j−1)(要求该格子存在)。
无法进行操作的玩家率先判负。
当双方均采取最优策略时,请判断哪位玩家获胜。
你将收到 T 组测试数据,请对每组数据分别求解。
输入格式
The input is given from Standard Input in the following format:
T
case1
case2
⋮
caseT
Each test case is given in the following format:
N K
A1,1 A1,2 … A1,N
A2,1 A2,2 … A2,N
⋮
AN,1 AN,2 … AN,N
输入从标准输入中按以下格式给出:
T
case1
case2
⋮
caseT
每个测试用例按以下格式给出:
N K
A1,1 A1,2 … A1,N
A2,1 A2,2 … A2,N
⋮
AN,1 AN,2 … AN,N
输出格式
Output the answers for the test cases in order, separated by newlines.
For each test case, output Alice if Alice wins when both play optimally, and Bob if Bob wins.
按顺序输出各测试用例的答案,答案之间用换行符分隔。
对每个测试用例,若双方均采取最优策略时 Alice 获胜,则输出 Alice;若 Bob 获胜,则输出 Bob。
输入输出样例
输入#1
3 2 2 0 1 3 2 3 1 1 1 1 1 1 1 1 1 1 4 4 3 8 5 3 4 2 0 6 0 9 10 4 1 9 7 10
输出#1
Alice Bob Alice
说明/提示
Sample 1 Explanation:
Consider the first test case.
For example, the game may proceed as follows (note that the players are not necessarily playing optimally):
- Alice's turn: Choose cell (2,2) and remove 2 stones. Move the removed stones to cell (1,2).
- Bob's turn: Choose cell (1,2) and remove 2 stones. Move the removed stones to cell (1,1).
- Alice's turn: Choose cell (2,1) and remove 2 stones. Move the removed stones to cell (1,1).
- Bob's turn: Choose cell (2,1) and remove 1 stone. Move the removed stone to cell (1,1).
- Alice's turn: Choose cell (1,2) and remove 1 stone. Move the removed stone to cell (1,1).
- Bob's turn: Bob cannot take a turn and loses.
By playing optimally, Alice can always beat Bob. Thus, output Alice on the first line.
Constraints
- 1≤T
- 2≤N≤100
- 1≤K≤109
- 0≤Ai,j≤109
- The sum of N2 over all test cases is at most 3×105.
- All input values are integers.
样例 1 解释:
考虑第一个测试用例。
例如,游戏可能按如下方式进行(注意:玩家未必采取最优策略):
- 爱丽丝的回合:选择格子 (2,2),移除 2 颗石子,并将这些被移除的石子移动到格子 (1,2)。
- 鲍勃的回合:选择格子 (1,2),移除 2 颗石子,并将这些被移除的石子移动到格子 (1,1)。
- 爱丽丝的回合:选择格子 (2,1),移除 2 颗石子,并将这些被移除的石子移动到格子 (1,1)。
- 鲍勃的回合:选择格子 (2,1),移除 1 颗石子,并将这颗被移除的石子移动到格子 (1,1)。
- 爱丽丝的回合:选择格子 (1,2),移除 1 颗石子,并将这颗被移除的石子移动到格子 (1,1)。
- 鲍勃的回合:鲍勃无法进行任何操作,因此判负。
若双方均采用最优策略,则爱丽丝总能击败鲍勃。因此,第一行输出 Alice。
限制条件
- 1≤T
- 2≤N≤100
- 1≤K≤109
- 0≤Ai,j≤109
- 所有测试用例中 N2 的总和不超过 3×105。
- 所有输入值均为整数。
输入解题思路,AI测评打分。不知道怎么写?