A14877 | Gojou and Matrix Game
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
Marin feels exhausted after a long day of cosplay, so Gojou invites her to play a game!
Marin and Gojou take turns to place one of their tokens on an $n \times n$ grid with Marin starting first. There are some restrictions and allowances on where to place tokens:
- Apart from the first move, the token placed by a player must be more than Manhattan distance $k$ away from the previous token placed on the matrix. In other words, if a player places a token at $(x_1, y_1)$ , then the token placed by the other player in the next move must be in a cell $(x_2, y_2)$ satisfying $|x_2 - x_1| + |y_2 - y_1| > k$ .
- Apart from the previous restriction, a token can be placed anywhere on the matrix, including cells where tokens were previously placed by any player.
Whenever a player places a token on cell $(x, y)$ , that player gets $v_{x,\ y}$ points. All values of $v$ on the grid are distinct. You still get points from a cell even if tokens were already placed onto the cell. The game finishes when each player makes $10^{100}$ moves.
Marin and Gojou will play $n^2$ games. For each cell of the grid, there will be exactly one game where Marin places a token on that cell on her first move. Please answer for each game, if Marin and Gojou play optimally (after Marin's first move), who will have more points at the end? Or will the game end in a draw (both players have the same points at the end)?
Marin and Gojou take turns to place one of their tokens on an $n \times n$ grid with Marin starting first. There are some restrictions and allowances on where to place tokens:
- Apart from the first move, the token placed by a player must be more than Manhattan distance $k$ away from the previous token placed on the matrix. In other words, if a player places a token at $(x_1, y_1)$ , then the token placed by the other player in the next move must be in a cell $(x_2, y_2)$ satisfying $|x_2 - x_1| + |y_2 - y_1| > k$ .
- Apart from the previous restriction, a token can be placed anywhere on the matrix, including cells where tokens were previously placed by any player.
Whenever a player places a token on cell $(x, y)$ , that player gets $v_{x,\ y}$ points. All values of $v$ on the grid are distinct. You still get points from a cell even if tokens were already placed onto the cell. The game finishes when each player makes $10^{100}$ moves.
Marin and Gojou will play $n^2$ games. For each cell of the grid, there will be exactly one game where Marin places a token on that cell on her first move. Please answer for each game, if Marin and Gojou play optimally (after Marin's first move), who will have more points at the end? Or will the game end in a draw (both players have the same points at the end)?
输入格式
The first line contains two integers $n$ , $k$ ( $3 \le n \le 2000$ , $1 \leq k \leq n - 2$ ). Note that under these constraints it is always possible to make a move.
The following $n$ lines contains $n$ integers each. The $j$ -th integer in the $i$ -th line is $v_{i,j}$ ( $1 \le v_{i,j} \le n^2$ ). All elements in $v$ are distinct.
The following $n$ lines contains $n$ integers each. The $j$ -th integer in the $i$ -th line is $v_{i,j}$ ( $1 \le v_{i,j} \le n^2$ ). All elements in $v$ are distinct.
输出格式
You should print $n$ lines. In the $i$ -th line, print $n$ characters, where the $j$ -th character is the result of the game in which Marin places her first token in the cell $(i, j)$ . Print 'M' if Marin wins, 'G' if Gojou wins, and 'D' if the game ends in a draw. Do not print spaces between the characters in one line.
输入输出样例
输入 #1
3 1 1 2 4 6 8 3 9 5 7
输出 #1
GGG MGG MGG
暂无题解
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted