AT_arc219_e.Equal Distribution

省选/NOI-

通过率:0%

时间限制:2.00s

内存限制:1024MB

AC君温馨提醒

该题目为【atcoder】题库的题目,您提交的代码将被提交至atcoder进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

There is a shortcake in the shape of a 2H×2W2H \times 2W grid. The cell at the ii-th row from the top and the jj-th column from the left is denoted as cell (i,j)(i,j). Cell (i,j)(i,j) has one strawberry on it if Si,j=S_{i,j}= o, and nothing if Si,j=S_{i,j}= x. It is guaranteed that exactly 2HW2HW cells have strawberries.

Divide each cell of this shortcake into regions A and B so that all of the following conditions are satisfied:

  • 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 2HW2HW cells each.
  • Both regions A and B contain exactly HWHW strawberries each.

It can be proved that such a partition always exists.

You are given TT test cases; solve each of them.

有一个形状为 2H×2W2H \times 2W 网格的蛋糕。从上往下第 ii 行、从左往右第 jj 列的格子记作格子 (i,j)(i,j)。若 Si,j=S_{i,j}= o,则格子 (i,j)(i,j) 上有一颗草莓;若 Si,j=S_{i,j}= x,则该格子上没有草莓。保证恰好有 2HW2HW 个格子上有草莓。

请将该蛋糕的每个格子划分至区域 A 或区域 B,使得以下所有条件均被满足:

  • 每个格子恰好属于区域 A 和区域 B 中的一个。
  • 区域 A 和区域 B 均为连通区域。即:对同一区域中的任意两个格子,均可通过在该区域内反复移动至相邻(共享一条边)的格子而相互到达。
  • 区域 A 和区域 B 各自恰好包含 2HW2HW 个格子。
  • 区域 A 和区域 B 各自恰好包含 HWHW 颗草莓。

可以证明,这样的划分总是存在的。

你将得到 TT 组测试数据;请对每组数据求解。

输入格式

The input is given from Standard Input in the following format:

TT
case1\text{case}_1
case2\text{case}_2
⋮\vdots
caseT\text{case}_T

Each test case is given in the following format:

HH WW
S1,1S1,2…S1,2WS_{1,1} S_{1,2} \ldots S_{1,2W}
S2,1S2,2…S2,2WS_{2,1} S_{2,2} \ldots S_{2,2W}
⋮\vdots
S2H,1S2H,2…S2H,2WS_{2H,1} S_{2H,2} \ldots S_{2H,2W}

输入从标准输入中按以下格式给出:

TT
case1\text{case}_1
case2\text{case}_2
⋮\vdots
caseT\text{case}_T

每个测试用例按以下格式给出:

HH WW
S1,1S1,2…S1,2WS_{1,1} S_{1,2} \ldots S_{1,2W}
S2,1S2,2…S2,2WS_{2,1} S_{2,2} \ldots S_{2,2W}
⋮\vdots
S2H,1S2H,2…S2H,2WS_{2H,1} S_{2H,2} \ldots S_{2H,2W}

输出格式

Output your solutions for the test cases in order, separated by newlines.

For each test case, output your solution in the following format:

X1,1X1,2…X1,2WX_{1,1} X_{1,2} \ldots X_{1,2W}
X2,1X2,2…X2,2WX_{2,1} X_{2,2} \ldots X_{2,2W}
⋮\vdots
X2H,1X2H,2…X2H,2WX_{2H,1} X_{2H,2} \ldots X_{2H,2W}

Here, Xi,jX_{i,j} is A if cell (i,j)(i,j) belongs to region A, and B if it belongs to region B.

If multiple valid partitions exist, any of them will be accepted.

按测试用例的顺序输出你的解答,各解答之间用换行符分隔。

对于每个测试用例,请按以下格式输出你的解答:

X1,1X1,2…X1,2WX_{1,1} X_{1,2} \ldots X_{1,2W}
X2,1X2,2…X2,2WX_{2,1} X_{2,2} \ldots X_{2,2W}
⋮\vdots
X2H,1X2H,2…X2H,2WX_{2H,1} X_{2H,2} \ldots X_{2H,2W}

其中,若单元格 (i,j)(i,j) 属于区域 A,则 Xi,jX_{i,j} 为 A;若属于区域 B,则 Xi,jX_{i,j} 为 B。

若存在多个合法划分方案,输出任意一种即可。

输入输出样例

  • 输入#1

    3
    1 1
    ox
    xo
    1 2
    oxxx
    ooxo
    2 3
    oooxxx
    oooxxx
    xoxxxx
    xooooo

    输出#1

    AA
    BB
    AAAB
    ABBB
    AAABBB
    AAAAAB
    ABABAB
    ABBBBB AB
    AB

说明/提示

Sample 1 Explanation:
Consider the first test case.

In the sample output, both regions A and B are connected and contain two cells each. Also, region A contains the strawberry at cell (1,1)(1,1), and region B contains the strawberry at cell (2,2)(2,2).

Additionally, for example, the following output is accepted:

Constraints

  • 1≤T1\le T
  • 1≤H≤W1\le H\le W
  • H×W≤106H\times W\le 10^6
  • Si,jS_{i,j} is o or x.
  • There are exactly 2HW2HW pairs (i,j)(i,j) with Si,j=S_{i,j}= o.
  • The sum of H×WH\times W over all test cases is at most 10610^6.
  • T,H,WT, H, W are integers.

样例 1 解释:
考虑第一个测试用例。

在样例输出中,区域 A 和区域 B 均为连通区域,且各自包含两个格子。此外,区域 A 包含位于格子 (1,1)(1,1) 的草莓,区域 B 包含位于格子 (2,2)(2,2) 的草莓。

另外,例如以下输出也是可接受的:

约束条件

  • 1≤T1\le T
  • 1≤H≤W1\le H\le W
  • H×W≤106H\times W\le 10^6
  • Si,jS_{i,j} 为 o 或 x。
  • 恰好有 2HW2HW 对 (i,j)(i,j) 满足 Si,j=S_{i,j}= o。
  • 所有测试用例的 H×WH\times W 之和不超过 10610^6。
  • T,H,WT, H, W 均为整数。

输入解题思路,AI测评打分。不知道怎么写?

首页