#P1764. 翻转游戏 (加强版)
翻转游戏 (加强版)
Description
kkke is playing a flip game on an board. Each cell of the board contains a piece, and each piece has faces: one black and one white. Initially, some pieces face up black and others face up white. Now kkke wants to make all pieces face the same color (either all black up or all white up) with the minimum number of flips. Each time a flip is performed, kkke may choose any piece to flip; at the same time, the pieces that are respectively adjacent to it up, down, left, and right must also be flipped.
Input Format
The first line contains an integer , indicating the board size is .
Then follow lines, each containing letters, representing the initial state of the board. If a letter is , the corresponding piece is currently white side up; if it is , the piece is currently black side up.
Output Format
Output one line. If it is impossible to reach the target state, output Impossible; otherwise, output a single integer, the minimum number of flips kkke needs.
4
bwwb
bbwb
bwwb
bwww
4
Hint
- Constraints
- For of the testdata, .
- For of the testdata, .
Translated by ChatGPT 5
京公网安备 11011102002149号