#P2594. [ZJOI2009] 染色游戏

    ID: 1607 远端评测题 1000ms 125MiB 尝试: 0 已通过: 0 难度: 8 上传者: 标签>递推博弈论2009各省省选浙江素数判断,质数,筛法

[ZJOI2009] 染色游戏

Description

There are n×mn \times m coins arranged in an n×mn \times m rectangle. Dongdong and Xixi play a game. In each move, a player may choose a connected component and flip all coins in it, but the move must satisfy: there exists a coin in this component such that all other coins in the component are in its upper-left (including directly to its left or directly above), and this coin is flipped from tails-up to heads-up. Dongdong and Xixi take turns. If a player cannot move, he or she loses. Dongdong moves first. Assuming both play optimally, determine whether Dongdong has a winning strategy.

Input Format

The first line contains a number TT, the number of games they play.

Then follow TT game descriptions. For each game, the first line contains two numbers n,mn, m.

Then there are nn lines, each with mm characters. In the ii-th line, the jj-th character is H if the coin at row ii, column jj is heads-up; otherwise it is tails-up. The upper-left of cell (i,j)(i, j) refers to the region with row index not exceeding ii and column index not exceeding jj.

Output Format

For each game, output one line. If Dongdong has a winning strategy, output -_-; otherwise, output =_=. Note that these are half-width characters, i.e., the three characters have ASCII codes 45, 61, and 95.

3
2 3
HHH
HHH
2 3
HHH
TTH
2 1
T
H
=_=
-_-
-_-

Hint

For 40%40\% of the testdata, 1n,m51 \le n,m \le 5.

For 100%100\% of the testdata, 1n,m100,1T501 \le n,m \le 100, 1 \le T \le 50.

Translated by ChatGPT 5