Logo
(追記) (追記ここまで)

34654번 - Grievous Lady 스페셜 저지다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
1 초 1024 MB155534842.857%

문제

You are given a grid of size $N \times M$. Your task is to color each cell of the grid with one of four colors: 1ドル,ドル 2ドル,ドル 3ドル,ドル or 4ドル$.

There is only one rule: any two adjacent cells must have different colors. Two cells are considered adjacent if they share a common edge.

Some cells in the grid may already be colored. These pre-colored cells are located only on the border of the grid. You must color all the remaining empty cells to create a complete grid that satisfies the rule.

입력

The first line of the input contains a single integer $T,ドル the number of test cases.

The first line of each test case contains two integers $N$ and $M$.

The next $N$ lines describe the initial state of the grid. Each line contains $M$ space-separated integers. A value of 0ドル$ represents an empty cell, while values from 1ドル$ to 4ドル$ represent a cell colored with that specific color.

출력

For each test case, output $N$ lines representing the completed grid.

Each line should contain $M$ space-separated integers, where each integer is a color from 1ドル$ to 4ドル$.

If multiple solutions exist, you may print any one of them.

제한

  • 1ドル \le T \le 8,000円$
  • 5ドル \le N, M \le 2 \cdot 10^5$
  • The sum of $N \times M$ over all test cases does not exceed 2ドル \cdot 10^5$.
  • In the initial grid, any non-zero cells are located only on the border (the first or last row, or the first or last column)
  • It is guaranteed that a solution always exists for the given input.

예제 입력 1

2
5 5
0 0 0 0 0
0 0 0 0 0
0 0 0 0 0
0 0 0 0 0
0 0 0 0 0
7 7
1 0 0 2 0 0 3
0 0 0 0 0 0 0
0 0 0 0 0 0 0
4 0 0 0 0 0 4
0 0 0 0 0 0 0
0 0 0 0 0 0 0
3 0 0 2 0 0 1

예제 출력 1

1 2 1 2 1
2 1 2 1 2
1 2 1 2 1
2 1 2 1 2
1 2 1 2 1
1 2 1 2 1 2 3
2 1 2 1 2 3 1
1 2 1 2 1 4 2
4 1 2 1 2 1 4
1 2 1 2 1 2 1
2 3 2 1 2 1 2
3 1 3 2 1 2 1

노트

출처

University > KAIST > KAIST ICPC Mock Competition > 2025 KAIST 15th ICPC Mock Competition G번

University > MIT > The MIT Programming Contest > 2025-26 > MIT Team Contest 2 G번

(追記) (追記ここまで)

출처

대학교 대회

  • 사업자 등록 번호: 541-88-00682
  • 대표자명: 최백준
  • 주소: 서울시 서초구 서초대로74길 29 서초파라곤 412호
  • 전화번호: 02-521-0487 (이메일로 연락 주세요)
  • 이메일: contacts@startlink.io
  • 통신판매신고번호: 제 2017-서울서초-2193 호

AltStyle によって変換されたページ (->オリジナル) /