CF1658E.Gojou and Matrix Game

普及/提高-

通过率:0%

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 x2x1+y2y1>k|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)(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)?

输入格式

The first line contains two integers nn , kk ( 3n20003 \le n \le 2000 , 1kn21 \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} ( 1vi,jn21 \le v_{i,j} \le n^2 ). All elements in vv are distinct.

输出格式

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.

输入输出样例

  • 输入#1

    3 1
    1 2 4
    6 8 3
    9 5 7

    输出#1

    GGG
    MGG
    MGG
首页