Account
GitHubFeedback
Drafts and results saved on this device
Submit on CSES.fi
CSES Problemset/Introductory Problems

Grid Coloring I

#3311
Ask AI

Open a hint-first prompt in a new AI chat. Grok may ask you to confirm before sending.

Open Claude Desktop

Time limit:1.00 s
Memory limit:512 MB
Unsolved
Download Tests (.zip)

You are given an n×mn\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

The first line has two integers nn and mm: the number of rows and columns.

The next nn lines each have mm characters: the description of the grid.

Output

Print nn lines each with mm characters: the description of the final grid.

You may print any valid solution.

If no solution exists, just print IMPOSSIBLE.

Constraints
  • 1≤n,m≤5001 \le n, m \le 500
Sample Test Cases (1)
Example 1ID: sample-1
Input
3 4
AAAA
BBBB
CCDD
Expected Output
CDCD
DCDC
ABAB
Tools
1
2
3
4
5
6
7
8
9
10
11
12
Draft saved locally
|1 line, 0 chars
Test Bench
Download .zip
Input (stdin)
3 4
AAAA
BBBB
CCDD
Expected Output
CDCD
DCDC
ABAB