均匀分配AI (CI翻译)
Problem Statement
题目描述
AI (CI翻译)There is a shortcake in the shape of a $2H \times 2W$ grid. The cell at the $i$-th row from the top and the $j$-th column from the left is denoted as cell $(i,j)$. Cell $(i,j)$ has one strawberry on it if $S_{i,j}=$ o, and nothing if $S_{i,j}=$ x. It is guaranteed that exactly $2HW$ cells have strawberries.
有一块形状为 $2H \times 2W$ 的网格蛋糕。从上往下数第 $i$ 行、从左往右数第 $j$ 列的单元格称为单元格 $(i,j)$。当 $S_{i,j}=$ o 时,单元格 $(i,j)$ 上有一颗草莓;当 $S_{i,j}=$ x 时,该单元格上没有草莓。保证恰好有 $2HW$ 个单元格上放有草莓。AI (CI翻译)
Divide each cell of this shortcake into regions A and B so that all of the following conditions are satisfied:
请将这块蛋糕的每个单元格划分到区域 A 或区域 B,使得满足以下所有条件:AI (CI翻译)
- Every cell belongs to exactly one of regions A and B.
- Both regions A and B are connected. That is, for any two cells in the same region, one can move between them by repeatedly moving to an adjacent cell (sharing an edge) in the same region.
- Both regions A and B contain exactly
$2HW$cells each. - Both regions A and B contain exactly
$HW$strawberries each.
- 每个单元格恰好属于区域 A 或区域 B 中的一个。
- 区域 A 和区域 B 都是连通的。也就是说,对于同一区域中的任意两个单元格,都可以通过反复移动到同一区域中与当前单元格共享一条边的相邻单元格,从一个单元格移动到另一个单元格。
- 区域 A 和区域 B 各包含恰好
$2HW$个单元格。 - 区域 A 和区域 B 各包含恰好
$HW$颗草莓。
It can be proved that such a partition always exists.
可以证明,这样的划分总是存在。AI (CI翻译)
You are given $T$ test cases; solve each of them.
给定 $T$ 组测试用例,请分别求出每组测试用例的答案。AI (CI翻译)
Constraints
约束条件
AI (CI翻译)$1\le T$$1\le H\le W$$H\times W\le 10^6$$S_{i,j}$isoorx.- There are exactly
$2HW$pairs$(i,j)$with$S_{i,j}=$o. - The sum of
$H\times W$over all test cases is at most$10^6$. $T, H, W$are integers.
$1\le T$$1\le H\le W$$H\times W\le 10^6$$S_{i,j}$为o或x。- 恰好有
$2HW$个有序对$(i,j)$满足$S_{i,j}=$o。 - 所有测试用例的
$H\times W$之和不超过$10^6$。 $T, H, W$均为整数。
Input
输入格式
AI (CI翻译)The input is given from Standard Input in the following format:
输入从标准输入按以下格式给出:AI (CI翻译)
T
\text{case}_1
\text{case}_2
\vdots
\text{case}_T
T
\text{case}_1
\text{case}_2
\vdots
\text{case}_TAI (CI翻译)
Each test case is given in the following format:
每组测试用例按以下格式给出:AI (CI翻译)
H W
S_{1,1} S_{1,2} \ldots S_{1,2W}
S_{2,1} S_{2,2} \ldots S_{2,2W}
\vdots
S_{2H,1} S_{2H,2} \ldots S_{2H,2W}
H W
S_{1,1} S_{1,2} \ldots S_{1,2W}
S_{2,1} S_{2,2} \ldots S_{2,2W}
\vdots
S_{2H,1} S_{2H,2} \ldots S_{2H,2W}AI (CI翻译)
Output
输出格式
AI (CI翻译)Output your solutions for the test cases in order, separated by newlines.
按测试用例的顺序输出答案,每组测试用例之间用换行分隔。AI (CI翻译)
For each test case, output your solution in the following format:
对于每组测试用例,按以下格式输出答案:AI (CI翻译)
X_{1,1} X_{1,2} \ldots X_{1,2W}
X_{2,1} X_{2,2} \ldots X_{2,2W}
\vdots
X_{2H,1} X_{2H,2} \ldots X_{2H,2W}
X_{1,1} X_{1,2} \ldots X_{1,2W}
X_{2,1} X_{2,2} \ldots X_{2,2W}
\vdots
X_{2H,1} X_{2H,2} \ldots X_{2H,2W}AI (CI翻译)
Here, $X_{i,j}$ is A if cell $(i,j)$ belongs to region A, and B if it belongs to region B.
其中,如果单元格 $(i,j)$ 属于区域 A,则 $X_{i,j}$ 为 A;如果属于区域 B,则 $X_{i,j}$ 为 B。AI (CI翻译)
If multiple valid partitions exist, any of them will be accepted.
如果存在多个满足条件的划分,输出其中任意一个即可通过。AI (CI翻译)
样例
3
1 1
ox
xo
1 2
oxxx
ooxo
2 3
oooxxx
oooxxx
xoxxxx
xooooo
AA
BB
AAAB
ABBB
AAABBB
AAAAAB
ABABAB
ABBBBB
题面与样例版权归 AtCoder 及出题人所有;中文翻译由 AI 生成(gpt-6.1-sol),如有出入请以原文为准。