QOJ.ac

QOJ

Time Limit: 2 s Memory Limit: 1024 MB Total points: 100

#12159. 住宅区

Statistics

ByteBud 公司计划建造一个充满公寓楼的住宅区。ByteBud 已经购买了一块矩形土地,并将其划分为 $n$ 行 $m$ 列。这样,公司将土地分成了 $n \cdot m$ 个矩形单元格。为方便起见,令坐标 $(i, j)$ 表示位于第 $i$ 行第 $j$ 列的单元格。他们需要选择一些单元格(可能是一个都不选,也可能是全部选择),并在每个选定的单元格上建造一栋公寓楼。你的任务是决定在哪些单元格上建造公寓楼,并确定每栋楼的高度(层数)。

设计过程并不简单!根据官方分区规定,坐标为 $(i, j)$ 的单元格上的楼房高度最多为 $h_{i,j}$ 层。特别地,如果 $h_{i,j} = 0$,则意味着该单元格上不能建造任何楼房。此外,ByteBud 已经为楼房之间的空间制定了初步规划。具体来说,对于地块上四个单元格交汇的每个点,他们已经规划了这些单元格上楼房高度的精确总和。对于每一对索引 $i \in \{1, \dots, n - 1\}, j \in \{1, \dots, m - 1\}$,你都会得到一个数字 $s_{i,j}$;该数字规定了坐标为 $(i, j), (i + 1, j), (i, j + 1), (i + 1, j + 1)$ 的单元格上的楼房高度总和必须恰好为 $s_{i,j}$ 层。

要求很多,ByteBud 今天就需要这个住宅区设计方案……所以,请检查是否存在满足所有要求的住宅区设计方案——如果存在,请给出一个有效的方案!

输入格式

输入的第一行包含两个整数 $n$ 和 $m$ ($2 \le n, m \le 300$),分别表示 ByteBud 将地块划分成的行数和列数。

接下来的 $n$ 行,第 $i$ 行包含 $m$ 个整数 $h_{i,1}, \dots, h_{i,m}$ ($0 \le h_{i,j} \le 10^{10}$);第 $j$ 个数字 $h_{i,j}$ 表示坐标为 $(i, j)$ 的单元格上公寓楼的最大高度(层数)。

接下来的 $n-1$ 行描述了楼房之间的初步空间规划。这 $n-1$ 行中的第 $i$ 行包含 $m-1$ 个整数 $s_{i,1}, \dots, s_{i,m-1}$ ($0 \le s_{i,j} \le 10^{10}$);第 $j$ 个数字 $s_{i,j}$ 指定了坐标为 $(i, j), (i+1, j), (i, j+1), (i+1, j+1)$ 的单元格上公寓楼高度总和的精确要求。

输出格式

如果存在满足所有要求的住宅区设计方案,请在输出的第一行打印 TAK。然后提供一个这样的设计示例,共 $n$ 行。第 $i$ 行应包含 $m$ 个非负整数 $x_{i,1}, \dots, x_{i,m}$,表示坐标为 $(i, 1), \dots, (i, m)$ 的单元格上公寓楼的高度(层数)。

如果不存在所需的设计方案,请在输出的唯一一行中打印 NIE

打印 TAKNIE 时,每个字符均可为大写或小写。

样例

样例输入 1

3 4
5 7 9 4
3 4 9 6
9 0 8 5
11 26 20
13 16 18

样例输出 1

TAK
0 6 9 3
1 4 7 1
8 0 5 5

样例输入 2

2 2
0 0
0 0
1000

样例输出 2

NIE

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.