제출 #464112

#제출 시각아이디문제언어결과실행 시간메모리
464112Alen777T-Covering (eJOI19_covering)C++17
0 / 100
16 ms24068 KiB
#include <iostream> #include <string> #include <iomanip> #include <vector> #include <set> #include <map> #include <queue> #include <stack> #include <cmath> #include <algorithm> #include <cstring> using namespace std; #define ll long long #define ull unsigned ll #define pb push_back #define mpr make_pair #define lb lower_bound #define ld long double #define ub upper_bound const int N = 1000005; vector<int> a[N]; void solve() { int n, m; cin >> n >> m; for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { int x; cin >> x; a[i].push_back(x); } } int k; cin >> k; bool flag = true; ll ans = 0; while (k--) { int x, y; cin >> x >> y; vector<pair<int, int> > v; for (int i = -1; i <= 1; i += 2) { if (x + i < n && x + i >= 0) { v.push_back(mpr(x + i, y)); } if (y + i < n && y + i >= 0) { v.push_back(mpr(x, y + i)); } } if (v.size() < 3) { flag = false; } else { int mn = 1005, sum = a[x][y]; for (auto i : v) { mn = min(mn, a[i.first][i.second]); sum += a[i.first][i.second]; } ans = ans + sum - mn; } } if (!flag) { cout << "NO" << endl; } else { cout << ans << endl; } } int main() { /*cout.setf(ios::fixed | ios::showpoint); cout.precision(6);*/ ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); solve(); return 0; }
#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...