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 ll long long
#define x first
#define y second
#define pb push_back
#define mp make_pair
#define all(a) (a).begin(), (a).end()
const int dx[4] = {-1, 0, 1, 0}, dy[4] = {0, 1, 0, -1};
const ll oo = 2e18;
int n, m;
ll **a;
bool ok(int i, int j) {
return i >= 0 && i < n && j >= 0 && j < m;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cin >> n >> m;
a = new ll*[n];
for (int i = 0; i < n; ++i) {
a[i] = new ll[m];
for (int j = 0; j < m; ++j) cin >> a[i][j];
}
ll ans = 0;
int k;
cin >> k;
while (k--) {
int r, c;
cin >> r >> c;
ll mx = -oo;
for (int i = 0; i < 4; ++i) {
bool OK = 1;
for (int j = 0; j < 4; ++j) {
if (j != i) OK &= ok(r + dx[j], c + dy[j]);
}
if (OK) {
ll q = a[r][c];
for (int j = 0; j < 4; ++j) {
if (j != i) q += a[r + dx[j]][c + dy[j]];
}
mx = max(mx, q);
}
}
ans += mx;
}
cout << ans;
return 0;
}
# | 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... |