wa求解
查看原帖
wa求解
1122530
elpsconr楼主2024/8/13 20:47

感觉很对,而且我看题解思路和我一样,不知道为什么wa了33个点

#include<bits/stdc++.h>
using namespace std;
#define int long long
#define PII pair<int,int>
#define tul tuple<int,int,int>
#define cy cout<<"YES"<<endl
#define cn cout<<"NO"<<endl
#define lc rt<<1
#define rc rt<<1|1
const int N=3e3+6,yyx=998244353;
int n,w,h,y,a[N][N],st[N][N];
int dx[]={0,1,0,-1},dy[]={1,0,-1,0};
int ans;
priority_queue<tul,vector<tul>,greater<tul> >q;
int bfs(int x){
    while(q.size()&&get<0>(q.top())<=x){
        auto [val,xx,yy]=q.top();q.pop();
        ans--;
        for(int i=0;i<4;++i){
            int px=xx+dx[i],py=yy+dy[i];
            if(px<1||py<1||px>h||py>w||st[px][py]) continue;
            st[px][py]=1;
            q.push({a[px][px],px,py});
        }
    }
    return ans;
}
inline void solve(){
  cin>>h>>w>>y;
  for(int i=1;i<=h;++i){
    for(int j=1;j<=w;++j) cin>>a[i][j];
  }
  for(int i=1;i<=h;++i){
    for(int j=1;j<=w;++j){
        if(i==1||j==1||i==h||j==w) st[i][j]=1,q.push({a[i][j],i,j});
    }
  }
  ans=h*w;
  for(int i=1;i<=y;++i){
    cout<<bfs(i)<<endl;
  }
}
signed main(){
   cin.tie(0)->sync_with_stdio(0);
   int _=1;
   //cin>>_;
   while(_--)
   solve();
   return 0;
}
2024/8/13 20:47
加载中...