CF1153B.Serval and Toy Bricks

普及-

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

Luckily, Serval got onto the right bus, and he came to the kindergarten on time. After coming to kindergarten, he found the toy bricks very funny.

He has a special interest to create difficult problems for others to solve. This time, with many 1×1×11 \times 1 \times 1 toy bricks, he builds up a 3-dimensional object. We can describe this object with a n×mn \times m matrix, such that in each cell (i,j)(i,j), there are hi,jh_{i,j} bricks standing on the top of each other.

However, Serval doesn't give you any hi,jh_{i,j}, and just give you the front view, left view, and the top view of this object, and he is now asking you to restore the object. Note that in the front view, there are mm columns, and in the ii-th of them, the height is the maximum of h1,i,h2,i,…,hn,ih_{1,i},h_{2,i},\dots,h_{n,i}. It is similar for the left view, where there are nn columns. And in the top view, there is an n×mn \times m matrix ti,jt_{i,j}, where ti,jt_{i,j} is 00 or 11. If ti,jt_{i,j} equals 11, that means hi,j>0h_{i,j} \gt 0, otherwise, hi,j=0h_{i,j}=0.

However, Serval is very lonely because others are bored about his unsolvable problems before, and refused to solve this one, although this time he promises there will be at least one object satisfying all the views. As his best friend, can you have a try?

幸运的是,小豹(Serval)坐上了正确的公交车,并准时到达了幼儿园。来到幼儿园后,他发现玩具积木非常有趣。

他对给他人设计难题有着特殊的兴趣。这一次,他用许多 1×1×11 \times 1 \times 1 的玩具积木搭建了一个三维物体。我们可以用一个 n×mn \times m 的矩阵来描述该物体:在每个格子 (i,j)(i,j) 上,竖直堆叠着 hi,jh_{i,j} 块积木。

然而,小豹并未直接给出任何 hi,jh_{i,j} 的值,而是仅提供了该物体的正视图、左视图和俯视图,并请你据此还原该物体。注意,在正视图中,共有 mm 列,其中第 ii 列的高度为 h1,i,h2,i,…,hn,ih_{1,i},h_{2,i},\dots,h_{n,i} 中的最大值;左视图同理,共有 nn 列;而在俯视图中,是一个 n×mn \times m 的矩阵 ti,jt_{i,j},其中每个 ti,jt_{i,j} 取值为 00 或 11:若 ti,j=1t_{i,j} = 1,表示 hi,j>0h_{i,j} > 0;否则 hi,j=0h_{i,j} = 0。

不过,小豹感到十分孤单——因为此前大家曾厌倦于他那些“无解”的难题,纷纷拒绝解决这道题。尽管这次他保证至少存在一个满足所有视图条件的物体,但依然无人响应。作为他最好的朋友,你愿意试一试吗?

输入格式

The first line contains three positive space-separated integers n,m,hn, m, h (1≤n,m,h≤1001\leq n, m, h \leq 100) — the length, width and height.

The second line contains mm non-negative space-separated integers a1,a2,…,ama_1,a_2,\dots,a_m, where aia_i is the height in the ii-th column from left to right of the front view (0≤ai≤h0\leq a_i \leq h).

The third line contains nn non-negative space-separated integers b1,b2,…,bnb_1,b_2,\dots,b_n (0≤bj≤h0\leq b_j \leq h), where bjb_j is the height in the jj-th column from left to right of the left view.

Each of the following nn lines contains mm numbers, each is 00 or 11, representing the top view, where jj-th number of ii-th row is 11 if hi,j>0h_{i, j} \gt 0, and 00 otherwise.

It is guaranteed that there is at least one structure satisfying the input.

第一行包含三个用空格分隔的正整数 n,m,hn, m, h(1≤n,m,h≤1001\leq n, m, h \leq 100),分别表示长、宽和高。

第二行包含 mm 个用空格分隔的非负整数 a1,a2,…,ama_1,a_2,\dots,a_m,其中 aia_i 表示从前视图中从左到右第 ii 列的高度(0≤ai≤h0\leq a_i \leq h)。

第三行包含 nn 个用空格分隔的非负整数 b1,b2,…,bnb_1,b_2,\dots,b_n(0≤bj≤h0\leq b_j \leq h),其中 bjb_j 表示从左视图中从左到右第 jj 列的高度。

接下来的 nn 行,每行包含 mm 个数字,每个数字为 00 或 11,表示俯视图;其中第 ii 行的第 jj 个数字为 11 当且仅当 hi,j>0h_{i, j} \gt 0,否则为 00。

保证至少存在一种结构满足输入条件。

输出格式

Output nn lines, each of them contains mm integers, the jj-th number in the ii-th line should be equal to the height in the corresponding position of the top view. If there are several objects satisfying the views, output any one of them.

输出 nn 行,每行包含 mm 个整数;第 ii 行的第 jj 个数应等于俯视图中对应位置的高度。若存在多个满足该视图的对象,输出其中任意一个即可。

输入输出样例

  • 输入#1

    3 7 3
    2 3 0 0 2 0 1
    2 1 3
    1 0 0 0 1 0 0
    0 0 0 0 0 0 1
    1 1 0 0 0 0 0

    输出#1

    1 0 0 0 2 0 0
    0 0 0 0 0 0 1
    2 3 0 0 0 0 0
  • 输入#2

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

    输出#2

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

说明/提示

The graph above illustrates the object in the first example.

The first graph illustrates the object in the example output for the second example, and the second graph shows the three-view drawing of it.

上图展示了第一个示例中的物体。

第一张图展示了第二个示例输出中的物体,第二张图展示了该物体的三视图。

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

首页