102013: [AtCoder]ABC201 D - Game in Momotetsu World

Memory Limit:256 MB Time Limit:2 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

Score : $400$ points

Problem Statement

We have a grid with $H$ rows and $W$ columns of squares, where each square is blue or red. The square at the $i$-th row and $j$-th column is blue if $A_{i, j}$ is +, and red if $A_{i, j}$ is -.
There is a piece on this grid, which is initially placed on the top-left square. Takahashi and Aoki will play a game using this piece.
Each of the two players has $0$ points in the beginning. They will alternately do the following operation, with Takahashi going first:

  • Move the piece one square right or one square down. It is not allowed to move the piece outside the grid. Then, the player (who moved the piece) gets one point if the piece is now on a blue square, and loses one point if the piece is now on a red square.

The game ends when one of the players is unable to do the operation. Then, the player with the greater number of points wins the game if they have different numbers of points. Otherwise, the game is drawn.
Find the result of the game when both players play the game to get the best outcome.

Constraints

  • $1 \le H, W \le 2000$
  • $A_{i, j}$ is + or -.

Input

Input is given from Standard Input in the following format:

$H$ $W$
$A_{1, 1}A_{1, 2}A_{1, 3} \dots A_{1, W}$
$A_{2, 1}A_{2, 2}A_{2, 3} \dots A_{2, W}$
$A_{3, 1}A_{3, 2}A_{3, 3} \dots A_{3, W}$
$\hspace{2cm}\vdots$
$A_{H, 1}A_{H, 2}A_{H, 3} \dots A_{H, W}$

Output

If Takahashi will win, print Takahashi; if Aoki will win, print Aoki; if the game will be drawn, print Draw.


Sample Input 1

3 3
---
+-+
+--

Sample Output 1

Takahashi

Takahashi has a winning strategy described below.

First, Takahashi moves the piece right, which makes him lose one point because the piece goes to a red square. Now, Takahashi has $-1$ point and Aoki has $0$ points. Then,

  • if Aoki moves the piece right, Takahashi moves it down;
  • if Aoki moves the piece down, Takahashi moves it right.

In either case, Aoki moves the piece to a red square losing one point, and Takahashi moves the piece to a blue square getting one point, which means now Takahashi has $0$ points and Aoki has $-1$ point.
The piece is now on the square at the $2$-nd row from the top and $3$-rd column from the left, and Aoki can only choose to move it down, to a red square. Now, Takahashi has $0$ points and Aoki has $-2$ points.
The piece cannot move right or down anymore, so the game ends. Since Takahashi has the greater number of points, he wins.


Sample Input 2

2 4
+++-
-+-+

Sample Output 2

Aoki

Aoki can win the game, regardless of what choices Takahashi makes.


Sample Input 3

1 1
-

Sample Output 3

Draw

In this case, the game immediately ends. Since both players have $0$ points, the game is drawn.

Input

题意翻译

给定一个 $W\times H$ 的棋盘,棋盘上每个点有两种颜色,蓝色(`+`)或红色(`-`)。 现在有一枚棋子位于 $(1,1)$ 处,`Takahashi` 和 `Aoki` 要轮流移动它,只能向右或向下移动, `Takahashi` 先手。 若任意一方将棋子移动到蓝色格子上,加一分,反之减一分。在棋子到达 $(W,H)$ 时,游戏结束,得分高者胜利。 假设双方都按照最优策略进行游戏,请问那方会赢?输出一行一个字符串 `Takahashi` 或 `Aoki`,平局则请输出 `Draw`。

加入题单

上一题 下一题 算法标签: