Cross Convolution
면접 대비시간 제한1.5초메모리 제한1024 MB
홀수 크기의 십자 모양 커널을 주어진 보폭으로 N×M 행렬 위에 놓을 때, 커널이 덮는 칸들의 합을 모든 유효 위치에 대해 출력한다.
문제
You are given an matrix . You are also given a special kernel of size , and a stride . Your task is to implement a convolution-like operation using a kernel with unique properties. The kernel must always remain completely within the matrix boundaries during its operation.
Specifically, the unique features of a kernel in this problem are:
- The kernel size is always an odd number.
- The kernel is filled with along the horizontal and vertical axes passing through the center and elsewhere.
For example, the following is the kernel when the size is and , respectively.
\[\begin{bmatrix} 0 & 1 & 0 \\ 1 & 1 & 1 \\ 0 & 1 & 0 \end{bmatrix} \qquad \begin{bmatrix} 0 & 0 & 1 & 0 & 0 \\ 0 & 0 & 1 & 0 & 0 \\ 1 & 1 & 1 & 1 & 1 \\ 0 & 0 & 1 & 0 & 0 \\ 0 & 0 & 1 & 0 & 0 \end{bmatrix}\]
The stride determines the step size for moving the kernel across the matrix. The kernel moves across the matrix based on the given stride. At each valid position (where the kernel fits entirely within the matrix boundaries), the element-wise sum of the matrix elements covered by the kernel is calculated.
Calculate a new matrix containing the sums from all valid kernel positions. The size of should be .
입력
The first line contains four space-separated integers: and , denoting the size of the image; , denoting the kernel size; and , denoting the stride. ( is a divisor of )
The following lines of input contain integers, where each line has space-separated integers, denoting the value of the matrix . Here, the -th integer of the -th line denotes . ()
출력
Output lines denoting the resulting matrix after applying the kernel with the given stride.
Each line should contain space-separated integers. The -th integer of the -th line should represent .