WA on 最后两个点
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int N = 551;
int P, Q, n, m, a[N][N], X, sum, dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};
bool vis[N][N];
struct Block {
int x, y;
};
bool cmp(Block p, Block q) {
return a[p.x][p.y] > a[q.x][q.y];
}
priority_queue<Block, vector<Block>, decltype(&cmp)>q(cmp);
void bfs() {
vis[P][Q] = 1;
q.push({P, Q});
while (q.size()) {
Block u = q.top();
q.pop();
if ((a[u.x][u.y]*X<sum)||(u.x==P&&u.y==Q)) {
sum+=a[u.x][u.y];
for (int i = 0; i < 4; i++) {
int xx = u.x + dx[i];
int yy = u.y + dy[i];
if (xx >= 1 && xx <= n && yy >= 1 && yy <= m && !vis[xx][yy]) {
vis[xx][yy] = 1;
q.push({xx, yy});
}
}
}else return;
}
}
signed main() {
ios::sync_with_stdio(0);
cin.tie(0);
cin >> n >> m >> X >> P >> Q;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= m; j++) {
cin >> a[i][j];
}
}
bfs();
cout<<sum;
return 0;
}