6768.Grid Coloring I

Time Limit: 1s Memory Limit: 512MB

You are given an $n\times m$ grid where each cell contains one character A , B , C or D .

For each cell, you must change the character to A , B , C or D . The new character must be different from the old one.

Your task is to change the characters in every cell such that no two adjacent cells have the same character.

Input Format(From the terminal/stdin)

The first line has two integers $n$ and $m$ : the number of rows and columns.

The next $n$ lines each have $m$ characters: the description of the grid.

  • $1 \le n, m \le 500$

Output Format(To the terminal/stdout)

Print $n$ lines each with $m$ characters: the description of the final grid.

You may print any valid solution.

If no solution exists, just print IMPOSSIBLE .

Sample Input

Copy
3 4
AAAA
BBBB
CCDD
 · \n
    \n
    \n
    \n

Sample Output special judge

Copy
CDCD
DCDC
ABAB
    \n
    \n
    \n
Source: CSES, Introductory Problems, 3311

Submit

请先 登录

© 2025 FAQs