36 lines
738 B
C
36 lines
738 B
C
|
#include <stdio.h>
|
||
|
#pragma gcc optimize("O2")
|
||
|
#define MAX 10
|
||
|
|
||
|
int matrixAdd(int matrix[][MAX], int m, int n, int x, int y);
|
||
|
|
||
|
int main(void) {
|
||
|
int m, n;
|
||
|
scanf("%d%d", &m, &n);
|
||
|
int matrix[m][MAX];
|
||
|
for (int i = 0; i < m; i++) {
|
||
|
for (int j = 0; j < n; j++) {
|
||
|
scanf("%d", &matrix[i][j]);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
int x, y;
|
||
|
scanf("%d%d", &x, &y);
|
||
|
printf("%d\n", matrixAdd(matrix, m, n, x - 1, y - 1));
|
||
|
|
||
|
return 0;
|
||
|
}
|
||
|
|
||
|
int matrixAdd(int matrix[][MAX], int m, int n, int x, int y) {
|
||
|
int sum = 0;
|
||
|
for (int i = -1; i <= 1; i++) {
|
||
|
for (int j = -1; j <= 1; j++) {
|
||
|
if (i + x >= 0 && i + x < m && j + y >= 0 && j + y < n &&
|
||
|
!(i == j && i == 0)) {
|
||
|
sum += matrix[i + x][j + y];
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
return sum;
|
||
|
}
|