#P2594. [ZJOI2009] 染色游戏
[ZJOI2009] 染色游戏
Description
There are coins arranged in an 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 , the number of games they play.
Then follow game descriptions. For each game, the first line contains two numbers .
Then there are lines, each with characters. In the -th line, the -th character is H if the coin at row , column is heads-up; otherwise it is tails-up. The upper-left of cell refers to the region with row index not exceeding and column index not exceeding .
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 of the testdata, .
For of the testdata, .
Translated by ChatGPT 5
京公网安备 11011102002149号