이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
/*#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("O3")
#pragma GCC target ("avx2")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")*/
#include<bits/stdc++.h>
#define sz(v) (int)v.size()
#define ll long long
#define pb push_back
#define x first
#define y second
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define nl "\n"
using namespace std;
using pii = pair<int, int>;
const int N = (int)2e5 + 7;
const int inf = (int)1e9 + 7;
const ll INF = (ll)1e18 + 7;
const ll MOD = (ll)1e9;
int n, m, k;
vector<vector<pii> > dir;
void solve() {
cin >> n >> m;
int a[n + 1][m + 1];
dir.pb({{-1, 0}, {0, -1}, {0, 1}});
dir.pb({{1, 0}, {0, -1}, {0, 1}});
dir.pb({{-1, 0}, {1, 0}, {0, 1}});
dir.pb({{-1, 0}, {1, 0}, {0, -1}});
for(int i = 1; i <= n; ++i) {
for(int j = 1; j <= m; ++j) {
cin >> a[i][j];
}
}
int ans = 0;
cin >> k;
while(k--) {
int mx = -inf;
int x, y;
cin >> x >> y;
x++, y++;
for(auto e : dir) {
int cur = a[x][y];
for(auto f : e) {
int i = x + f.x, j = y + f.y;
if(i < 1 || i > n || j < 1 || j > m) {
cur = -inf;
break;
}
cur += a[i][j];
}
mx = max(mx, cur);
}
ans += mx;
if(mx == -inf) {
cout << "No\n";
return;
}
}
cout << ans << nl;
}
signed main() {
ios_base::sync_with_stdio(NULL);
cin.tie(0);
cout.tie(0);
int test = 1;
//cin >> test;
while(test--) {
solve();
}
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... |