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 <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <ctime>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <limits>
#include <iomanip>
#include <unordered_set>
#include <unordered_map>
#include <fstream>
#include <random>
using namespace std;
typedef long long ll;
typedef double ld;
typedef int itn;
#define ff first
#define ss second
ll ttt;
const ll INF = 1e18;
const ll SAFEINF = 1e12;
const ll MOD = 1e9 + 7;
const ll MOD2 = 998244353;
const ll MOD3 = 32768;
const ll N = 2e5 + 7;
ll n, m, k;
vector<vector<ll>>a;
vector<vector<bool>>sp;
int main() {
cin >> n >> m;
sp.resize(n + 1, vector<bool>(m + 1, false));
a.push_back(vector<ll>(m + 2, 0));
for (int i = 1; i <= n; i++) {
a.push_back(vector<ll>(m + 2, 0));
for (int j = 1; j <= m; j++) {
cin >> a[i][j];
}
}
a.push_back(vector<ll>(m + 2, 0));
cin >> k;
bool ok = true;
for (int i = 0; i < k; i++) {
ll x, y;
cin >> x >> y;
x++, y++;
if (x == 0 || x == n) {
if (y == 0 || y == n) {
ok = false;
}
}
sp[x][y] = true;
}
if (!ok) {
cout << "NO" << endl;
return 0;
}
ll ans = 0;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n; j++) {
if (sp[i][j]) {
ll mn = min({ a[i][j - 1],a[i][j + 1],a[i - 1][j],a[i + 1][j] });
ans += a[i][j] + a[i][j - 1] + a[i][j + 1]
+ a[i - 1][j] + a[i + 1][j] - mn;
}
}
}
cout << ans << endl;
return 0;
}
/*
4 20
2
3
2
2
*/
# | 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... |