昨天ABC E求条
  • 板块学术版
  • 楼主Igallta
  • 当前回复6
  • 已保存回复6
  • 发布时间2024/12/15 09:49
  • 上次更新2024/12/15 10:07:00
查看原帖
昨天ABC E求条
813622
Igallta楼主2024/12/15 09:49

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;
}
2024/12/15 09:49
加载中...