#include <iostream>
using namespace std;
#include <vector>
int n, m, k;
long long sum;
int s;
void put(int i, int j, int p, vector<vector<int>> &num) {
sum += num[i][j];
sum += num[i + 1][j];
sum += num[i -1][j];
sum += num[i][j + 1];
sum += num[i][j - 1];
if (p == 3) {
sum -= num[i + 1][j];
}
if (p == 2) {
sum -= num[i - 1][j];
}
if (p == 1) {
sum -= num[i][j + 1];
}
if (p == 0) {
sum -= num[i][j - 1];
}
}
int main()
{
cin >> m;
cin >> n;
vector<vector<int>> num(m+1);
vector<vector<int>> pain(m+1);
s = 1;
for (int i = 0; i < m; i++) {
//pain[i].resize(n+1);
for (int j = 0; j < n; j++) {
int x;
cin >> x;
num[i].push_back(x);
pain[i].push_back(0);
}
num[i].push_back(0);
}
cin >> k;
for (int i = 0; i < k; i++) {
int a, b;
cin >> a;
cin >> b;
pain[a][b] = 1;
}
for (int i = 0; i < m; i++) {
for (int j = 0; j < n; j++) {
if (pain[i][j] == 1) {
int min = 1001;
if (pain[i - 1][j] == 1) {
if (i == m - 1 || j == n - 1) {
s = 0;
}
put(i, j, 2,num);
continue;
}
if (pain[i + 1][j] == 1) {
if (i == m - 1 || j == n - 1) {
s = 0;
}
put(i, j, 3,num);
continue;
}
if (pain[i][j+1] == 1) {
if (i == m - 1 || j == n - 1) {
s = 0;
}
put(i, j, 1,num);
continue;
}
if (pain[i][j - 1] == 1) {
if (i == m - 1 || j == n - 1) {
s = 0;
}
put(i, j, 0,num);
continue;
}
if (min > num[i + 1][j]) {
min = num[i + 1][j];
}
if (min > num[i - 1][j]) {
min = num[i - 1][j];
}
if (min > num[i][j+1]) {
min = num[i][j+1];
}
if (min > num[i ][j-1]) {
min = num[i][j-1];
}
sum += num[i][j];
sum += num[i + 1][j];
sum += num[i - 1][j];
sum += num[i][j + 1];
sum += num[i][j - 1];
sum -= min;
}
}
}
if (s == 0) {
cout << "NO";
}
else {
cout << sum;
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
332 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
6 ms |
2252 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
332 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
415 ms |
65540 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
332 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |