调了一个晚上了,__int128开满了,还是WA了两个点,要气死了。
评测记录:link
代码:
#include<bits/stdc++.h>
#define int __int128
using namespace std;
int h,w,p,q,x,dx[4]={1,0,0,-1},dy[4]={0,-1,1,0};
int s[505][505];
bool vis[505][505];
struct node{
int x,y;
bool operator<(const node &o)const{
return s[x][y]>s[o.x][o.y];
}
bool operator==(const node &o)const{
return x==o.x&&y==o.y;
}
};
multiset<node>st;
long long ih,iw,ix,ip,iq;
signed main(){
cin>>ih>>iw>>ix>>ip>>iq;
h=ih;
w=iw;
x=ix;
p=ip;
q=iq;
for(int i=1;i<=h;i++){
for(int j=1;j<=w;j++){
long long is;
cin>>is;
s[i][j]=is;
}
}
vis[p][q]=1;
for(int i=0;i<4;i++){
if(p+dx[i]>=1&&p+dx[i]<=h&&q+dy[i]>=1&&q+dy[i]<=w)st.insert({p+dx[i],q+dy[i]}),vis[p+dx[i]][q+dy[i]]=1;
}
s[502][502]=floor((s[p][q]-1)*1.0/x);
while(!st.empty()){
auto a=(st.lower_bound({502,502}));
if(a==st.end())break;
node n=*a;
int tx=n.x,ty=n.y;
st.erase({tx,ty});
s[p][q]+=s[tx][ty];
s[502][502]=floor((s[p][q]-1)*1.0/x);
for(int i=0;i<4;i++){
if(tx+dx[i]>=1&&tx+dx[i]<=h&&ty+dy[i]>=1&&ty+dy[i]<=w&&vis[tx+dx[i]][ty+dy[i]]==0)st.insert({tx+dx[i],ty+dy[i]}),vis[tx+dx[i]][ty+dy[i]]=1;
}
}
cout<<(long long)s[p][q];
}