求助
  • 板块灌水区
  • 楼主CNzzc
  • 当前回复1
  • 已保存回复1
  • 发布时间2024/12/14 22:55
  • 上次更新2024/12/15 10:22:23
查看原帖
求助
750689
CNzzc楼主2024/12/14 22:55

atcoder今晚E题WA2个点求调

#include<bits/stdc++.h>
#define int long long
#define endl '\n'
#define pr(x) pair<x,x>
#define up(i,j,k,l) for(int i=j;i<=k;i+=l)
#define down(i,j,k,l) for(int i=j;i>=k;i-=l)
using namespace std;
const int N=5e2+10,YL=1;
int h,w,x,p,q;
int a[N][N];
struct node{
	int z,x,y;
};
const int dx[4]={-1,0,0,1},dy[4]={0,-1,1,0};
int res,sz;
bool f[N][N];
bool operator<(node x1,node x2)
{
	return x1.z>x2.z;
}
priority_queue<node> py;
bool check(int x,int y)
{
	if(x<1 || y<1 || x>h || y>w){
		return false;
	}
	else{
		return true;
	}
}
void bfs()
{
	f[p][q]=true;
	py.push({a[p][q],p,q});
	node t;
	int xx,yy;
	while(!py.empty()){
		t=py.top();
		py.pop();
		if((t.x==p && t.y==q) || YL*t.z*x<res){
			res+=t.z;
		}
		else{
			break;
		}
		up(i,0,3,1){
			xx=t.x+dx[i];
			yy=t.y+dy[i];
			if(check(xx,yy) && f[xx][yy]==false){
				f[xx][yy]=true;
				py.push({a[xx][yy],xx,yy});
			}
		}
	}
	return;
}
void solve()
{
	cin>>h>>w>>x>>p>>q;
	up(i,1,h,1){
		up(j,1,w,1){
			cin>>a[i][j];
		}
	}
	bfs();
	cout<<res<<endl;
	return;
}
signed main()
{
    //ios::sync_with_stdio(false);
	//cin.tie(0);
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	int _=1;
	//cin>>_;
	up(i,1,_,1){
		solve();
	}
	return 0;
}
2024/12/14 22:55
加载中...