이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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 == 1 || x == n) {
if (y == 1 || y == m) {
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 <= m; 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... |