This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
#define int long long
int n, m, k;
struct Tetro
{
int x, y;
};
vector<vector<int>> grid;
vector<Tetro> tetros;
signed main()
{
cin.tie(0);
ios_base::sync_with_stdio(false);
cin >> m >> n;
grid = vector<vector<int>>(n, vector<int>(m));
for (int y = 0; y < m; y++)
for (int x = 0; x < n; x++)
cin >> grid[x][y];
cin >> k;
tetros = vector<Tetro>(k);
for (int i = 0; i < k; i++)
{
int x, y;
cin >> y >> x;
tetros[i] = {x, y};
// make sure it is possible to place the current tetro
if ((x == 0 || x == n - 1) && (y == 0 || y == m - 1))
{
cout << "No";
return 0;
}
}
int solution = 0;
for (Tetro t : tetros)
{
int a = grid[t.x + 1][t.y + 0];
int b = grid[t.x - 1][t.y + 0];
int c = grid[t.x + 0][t.y + 1];
int d = grid[t.x + 0][t.y - 1];
solution += a + b + c + d - min(a, min(b, min(c, d)));
}
cout << solution;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |