#B4345. [语言月赛 202506] 卷积画图
[语言月赛 202506] 卷积画图
题目描述
给定一张 的画布(每个格子里有一个数字),以及一个 的“模板”。我们要把这个模板放在画布的左上角,然后一点一点向右、向下移动。每次移动的时候,把模板里的数字和画布上对应的数字相乘,然后加起来,得到一个新数字。这样,我们就会得到一张新的、稍小的画布。这个过程叫“卷积”。
例如,假设我们有这样一张 的画布:
$$\begin{bmatrix} 1 & 2 & 3 \\ 4 & 5 & 6 \\ 7 & 8 & 9 \end{bmatrix}, $$及这样一张 的模板:
执行“卷积”后,我们可以得到以下结果:
$$\begin{bmatrix} a & b \\ c & d \\ \end{bmatrix} = \begin{bmatrix} 36 & 47 \\ 69 & 80 \\ \end{bmatrix} , $$其中: | 结果变量 | 对应画布位置 | 模板 | 结果 | | :-: | :-: | :-: | :-: | | | $\begin{bmatrix} \color{red}{1} & \color{orange}{2} & 3 \\ \color{green}{4} & \color{blue}{5} & 6 \\ 7 & 8 & 9 \end{bmatrix}$ | $\begin{bmatrix} \color{red}{3} & \color{orange}{2} \\ \color{green}{1} & \color{blue}{5} \end{bmatrix}$ | ${\color{red}{1}} \times {\color{red}{3}} + {\color{orange}{2}} \times {\color{orange}{2}} + {\color{green}{4}} \times {\color{green}{1}} + {\color{blue}{5}} \times {\color{blue}{5}} = 36$ | | | $\begin{bmatrix} 1 & \color{red}{2} & \color{orange}{3} \\ 4 & \color{green}{5} & \color{blue}{6} \\ 7 & 8 & 9 \end{bmatrix}$ | $\begin{bmatrix} \color{red}{3} & \color{orange}{2} \\ \color{green}{1} & \color{blue}{5} \end{bmatrix}$ | ${\color{red}{2}} \times {\color{red}{3}} + {\color{orange}{3}} \times {\color{orange}{2}} + {\color{green}{5}} \times {\color{green}{1}} + {\color{blue}{6}} \times {\color{blue}{5}} = 47$ | | | $\begin{bmatrix} 1 & 2 & 3 \\ \color{red}{4} & \color{orange}{5} & 6 \\ \color{green}{7} & \color{blue}{8} & 9 \end{bmatrix}$ | $\begin{bmatrix} \color{red}{3} & \color{orange}{2} \\ \color{green}{1} & \color{blue}{5} \end{bmatrix}$ | ${\color{red}{4}} \times {\color{red}{3}} + {\color{orange}{5}} \times {\color{orange}{2}} + {\color{green}{7}} \times {\color{green}{1}} + {\color{blue}{8}} \times {\color{blue}{5}} = 69$ | | | $\begin{bmatrix} 1 & 2 & 3 \\ 4 & \color{red}{5} & \color{orange}{6} \\ 7 & \color{green}{8} & \color{blue}{9} \end{bmatrix}$ | $\begin{bmatrix} \color{red}{3} & \color{orange}{2} \\ \color{green}{1} & \color{blue}{5} \end{bmatrix}$ | ${\color{red}{5}} \times {\color{red}{3}} + {\color{orange}{6}} \times {\color{orange}{2}} + {\color{green}{8}} \times {\color{green}{1}} + {\color{blue}{9}} \times {\color{blue}{5}} = 80$ |
现在给定画布和模板,请你算出卷积之后的画布内容。
输入格式
输入共 行。
第一行三个整数 ,分别表示画布的大小和模板的大小;
接下来 行,每行 个整数,表示原始画布;
接下来 行,每行 个整数,表示模板内容。
输出格式
输出 行,每行 个整数,代表一张大小为 的卷积结果。
3 3 2
1 2 3
4 5 6
7 8 9
3 2
1 5
36 47
69 80
4 4 2
1 2 1 2
3 4 3 4
5 6 5 6
7 8 7 8
1 1
1 1
10 10 10
18 18 18
26 26 26
7 10 3
9 7 8 10 8 5 1 9 10 5
5 2 3 1 1 5 1 1 1 3
1 10 9 5 5 2 1 8 6 1
10 1 8 10 1 3 1 1 8 5
7 9 2 2 4 3 1 1 1 1
5 5 1 9 4 1 7 10 7 10
10 8 9 3 1 10 1 6 1 9
1 7 1
2 9 5
1 1 9
201 173 165 135 112 120 153 133
242 249 126 116 83 79 187 140
183 231 200 119 70 50 125 161
149 200 167 97 131 129 112 185
231 133 144 186 98 191 164 230
提示
数据规模与约定
本题共 个测试点。对于 的测试数据,,,所有输入数据中的整数都在 到 之间。
测试点编号 | 特殊性质 | ||
---|---|---|---|
无 | |||
“模板”内的整数全为 | |||
无 |