제출 #638537

#제출 시각아이디문제언어결과실행 시간메모리
638537gagik_2007T-Covering (eJOI19_covering)C++17
5 / 100
190 ms8712 KiB
#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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...