CF1658E.Gojou and Matrix Game

省选/NOI-

通过率:0%

时间限制:4.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

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×nn \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 kk away from the previous token placed on the matrix. In other words, if a player places a token at (x1,y1)(x_1, y_1), then the token placed by the other player in the next move must be in a cell (x2,y2)(x_2, y_2) satisfying ∣x2−x1∣+∣y2−y1∣>k|x_2 - x_1| + |y_2 - y_1| \gt 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)(x, y), that player gets vx, yv_{x,\ y} points. All values of vv 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 1010010^{100} moves.

Marin and Gojou will play n2n^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 经过一整天的 Cosplay 后感到筋疲力尽,于是 Gojou 邀请她一起玩游戏!

Marin 和 Gojou 轮流在一个 n×nn \times n 的网格上放置各自的棋子,Marin 先手。棋子的放置需满足以下限制与允许条件:

  • 除第一步外,当前玩家所放置的棋子必须与上一次(即对方)所放置的棋子之间的曼哈顿距离严格大于 kk。换言之,若某玩家将棋子置于 (x1,y1)(x_1, y_1),则另一玩家在下一步所放置的棋子必须位于满足 ∣x2−x1∣+∣y2−y1∣>k|x_2 - x_1| + |y_2 - y_1| \gt k 的格子 (x2,y2)(x_2, y_2) 上。
  • 除上述限制外,棋子可放置于网格中任意位置,包括已被任一玩家放置过棋子的格子。

每当一名玩家在格子 (x,y)(x, y) 上放置一枚棋子,该玩家即获得 vx, yv_{x,\ y} 分。网格中所有 vv 值互不相同。即使某个格子上已存在棋子,再次在该格子上放置棋子仍可获得对应分数。游戏持续进行,直至双方各自完成 1010010^{100} 步。

Marin 和 Gojou 将共进行 n2n^2 局游戏。对于网格中的每个格子,恰好有一局游戏中 Marin 的第一步是将棋子放在该格子上。请对每一局游戏回答:若 Marin 和 Gojou 在 Marin 第一步之后均采取最优策略,最终谁的总分更高?还是游戏以平局结束(双方最终得分相等)?

输入格式

The first line contains two integers nn, kk (3≤n≤20003 \le n \le 2000, 1≤k≤n−21 \leq k \leq n - 2). Note that under these constraints it is always possible to make a move.

The following nn lines contains nn integers each. The jj-th integer in the ii-th line is vi,jv_{i,j} (1≤vi,j≤n21 \le v_{i,j} \le n^2). All elements in vv are distinct.

第一行包含两个整数 nn 和 kk(3≤n≤20003 \le n \le 2000,1≤k≤n−21 \leq k \leq n - 2)。注意,在这些约束条件下,总是可以执行一次操作。

接下来的 nn 行,每行包含 nn 个整数。第 ii 行中的第 jj 个整数为 vi,jv_{i,j}(1≤vi,j≤n21 \le v_{i,j} \le n^2)。数组 vv 中的所有元素互不相同。

输出格式

You should print nn lines. In the ii-th line, print nn characters, where the jj-th character is the result of the game in which Marin places her first token in the cell (i,j)(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.

你需要输出 nn 行。在第 ii 行中,输出 nn 个字符,其中第 jj 个字符表示 Marin 将她的第一个棋子放置在格子 (i,j)(i, j) 时该对局的结果:若 Marin 获胜,输出 'M';若 Gojou 获胜,输出 'G';若平局,输出 'D'。同一行中的字符之间不要添加空格。

输入输出样例

  • 输入#1

    3 1
    1 2 4
    6 8 3
    9 5 7

    输出#1

    GGG
    MGG
    MGG

输入解题思路,AI测评打分。不知道怎么写?

首页