Codeforces 1153 B Serval and Toy Bricks

http://codeforces.com/problemset/problem/1153/B

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×1×1 toy bricks, he builds up a 3-dimensional object. We can describe this object with a n×mn×m matrix, such that in each cell (i,j)(i,j) , there are hi,jhi,j bricks standing on the top of each other.

However, Serval doesn't give you any hi,jhi,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,ih1,i,h2,i,…,hn,i . It is similar for the left view, where there are nn columns. And in the top view, there is an n×mn×m matrix ti,jti,j , where ti,jti,j is 00 or 11 . If ti,jti,j equals 11 , that means hi,j>0hi,j>0 , otherwise, hi,j=0hi,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?

Input

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

The second line contains mm non-negative space-separated integers a1,a2,…,ama1,a2,…,am , where aiai is the height in the ii -th column from left to right of the front view (0≤ai≤h0≤ai≤h ).

The third line contains nn non-negative space-separated integers b1,b2,…,bnb1,b2,…,bn (0≤bj≤h0≤bj≤h ), where bjbj 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>0hi,j>0 , and 00 otherwise.

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

Output

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.

Examples

Input

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

Output

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

Input

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

Output

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

题目大意:给出一个立体图形,高度最高为h,第一行给出n、m、h,第二行给出正视图每一列的高度(共m列),第三行给出左视图每一列的高度(共n列),然后有n*m个数,若其值为0,则意味着该处高度为0;若其值为1,则意味着该处高度不为0。求满足题意的立体图形的每一处的高度。(有多个解输出任意一个即可)

思路:思维题目,设序列A存储正视图m列的高度,序列B存储左视图n列的高度,二维数组C存储n*m的01矩阵,若Cij=0,则该处答案为0,(因为高度为0)否则输出min(A[i],B[j])。(这样一定满足题意)

#include<iostream>
#include<cstdio>
#include<queue>
#include<cmath>
#include<algorithm>
#include<cstring>
#define INF 0x3f3f3f3f
using namespace std ;

int a[105];
int b[105];
int n,m,h;

int main()
{
    scanf("%d %d %d",&n,&m,&h);
    for(int i=0;i<m;i++)
        scanf("%d",&b[i]);
    for(int i=0;i<n;i++)
        scanf("%d",&a[i]);
    int t;
    for(int i=0;i<n;i++)
    {
        for(int j=0;j<m;j++)
        {
            scanf("%d",&t);
            if(j)
                putchar(' ');
            if(t==0)
                printf("0");
            else
                printf("%d",min(a[i],b[j]));
        }
        putchar('\n');
    }
    return 0;
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值