ABC-384-E - Takahashi is Slime 2 · znzryb
## 思路讲解
[https://www.luogu.com.cn/discuss/1021064](https://www.luogu.com.cn/discuss/1021064)
没什么其他要注意的,就是注意long double才能保证在long long范围内不被卡精度
```cpp
maze[x][y]*1.0l <ans*1.0l/X
```
## AC代码
[https://atcoder.jp/contests/abc384/submissions/62254421](https://atcoder.jp/contests/abc384/submissions/62254421)
```cpp
#include <bits/stdc++.h>
#define FOR(i, a, b) for (int i = a; i <= b; ++i)
#define ROF(i, a, b) for (int i = a; i >= b; --i)
#define all(x,size) x.begin()+1,x.begin()+size+1
#define all1(x) x.begin(),x.end()
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll> pll;
typedef array<ll,3> arr;
typedef double DB;
const ll MAXN=510,MAXval=static_cast<ll>(1e18)+3;
ll N,M,X,sx,sy;
ll maze[MAXN][MAXN];
bool vis[MAXN][MAXN];
struct cmp{
bool operator()(pll a,pll b){
return maze[a.first][a.second]>maze[b.first][b.second];
}
};
ll dx[4]={1,0,-1,0};
ll dy[4]={0,1,0,-1};
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);cout.tie(0);
cin>>N>>M>>X>>sx>>sy;
FOR(i, 1, N){
FOR(j, 1, M){
cin>>maze[i][j];
}
}
priority_queue<pll,vector<pll>,cmp> pq;
pq.push({sx,sy});
vis[sx][sy]=true;
ll ans=0;
// cout<<"Yes\n";
while (!pq.empty()) {
ll x=pq.top().first,y=pq.top().second;
pq.pop();
if(maze[x][y]*1.0l <ans*1.0l/X || (x==sx && y==sy)){
ans+=maze[x][y];
// cout<<ans<< ' '<< x <<' '<< y <<'\n';
FOR(i, 0, 3){
ll fx=x+dx[i],fy=y+dy[i];
if(fx<1 || fx>N) continue;
if(fy<1 || fy>M) continue;
if(vis[fx][fy]) continue;
vis[fx][fy]=true;
pq.push({fx,fy});
}
}
}
cout<<ans<<'\n';
return 0;
}
/*
3 3 2
2 2
14 6 9
4 9 20
17 15 7
*/
```
## 心路历程(WA,TLE,MLE……)