본문 바로가기

코드포스

[코드포스 Practice3] C. Serval and Toy Bricks

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 (1n,m,h1001≤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 (0aih0≤ai≤h).

The third line contains nn non-negative space-separated integers b1,b2,,bnb1,b2,…,bn (0bjh0≤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.

 

 

 

영어공부하겠다고 번역 해볼려 했더니 싫어서 미루게 된다ㅋㅋㅋ 그냥 한거나 정리하고 다음에 심심할 때 번역해야겠음


문제 처음 읽을 때 음?? 이걸 어케 구하지? 싶었다. 사실 이 문제만 그런 건 아니고 모든 문제가 다 그렇다

이건 풀면서 입력 출력 정의한 거

 

처음에는 경우를 나눠서 한 줄이 전부 0이고 하나만 1이면 그 값은 top에 있는 값으로 채우고 나머지 경우를 또 찾아보려 했다. 그런데 생각해보니깐 그냥 가로 세로 중 작은 값을 선택하면 될 거 같았다. 게다가 Brick을 최소로 쓰라는 조건도 없다!

 

#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
 
int main() {
    int n, m, h;
    scanf("%d %d %d", &n, &m, &h);
    
    vector<int>vn(n);
    vector<int>vm(m);
    vector<vector<int>> vt(n, vector<int>(m));
    
    for(int i = 0; i < m; i++)
        scanf("%d", &vm[i]);
    
    for(int i = 0; i < n; i++)
        scanf("%d", &vn[i]);
        
    for(int i = 0; i < n; i++){
        for(int j = 0; j < m; j++)
            scanf("%d", &vt[i][j]);
    }
        
    for(int i = 0; i < n; i++){
        for(int j = 0; j < m; j++){
            if(vt[i][j] == 1){
                vt[i][j] = min(vm[j], vn[i]);
            }
        }
    }
    
    for(int i = 0; i < n; i++){
        for(int j = 0; j < m; j++)
            printf("%d ", vt[i][j]);
        printf("\n");
    }
    
    
    
    return 0;
}

그래서 코드도 간단하다. 그냥 입력 받고 가로, 세로 중 최소값을 찾아서 변경해 준 다음 출력해줬다. 

 

int main()
{
	int n, m, h;
	scanf("%d %d %d", &n, &m, &h);

	vector<int> a(m);
	vector<int> b(n);

	for (int i = 0; i < m; i++)
		scanf("%d", &a[i]);

	for (int i = 0; i < n; i++)
		scanf("%d", &b[i]);

	for (int i = 0; i < n; i++)
	{
		for (int j = 0; j < m; j++)
		{
			int now;
			scanf("%d", &now);

			if (now == 0)
				printf("0 ");
			else
				printf("%d ", min(a[j], b[i]));
		}
		printf("\n");
	}

	return 0;
}

움 북님 코드랑 비슷하군

그러게 배열 만들 필요 없이 그냥 0이 아니면 최솟값 찾아서 출력해주면 됐었다.