捞捞捞(关于病毒代码
查看原帖
捞捞捞(关于病毒代码
1291285
封禁用户楼主2024/8/4 23:04

求条,悬赏 3 个关注

#include<bits/stdc++.h>
using namespace std;
#define int long long
const int N=1e3+5,M=1e5+5;
int a[N][N],ans[N];
bool vis[N][N];
int dx[4]={0,0,1,-1};
int dy[4]={1,-1,0,0};
priority_queue<array<int,3>, vector<array<int,3> >, greater<array<int,3> > > pq;
signed main(){
    int n,m,k;
    cin>>n>>m>>k;
    for(int i=1;i<=n;++i){
        for(int j=1;j<=m;++j){
            cin>>a[i][j];
            if(i==1||j==1||i==m||j==m){
                pq.push({a[i][j],i,j});
                vis[i][j]=1;
            }
        }
    }
    int now=0;
    while(!pq.empty()){
        auto tmp=pq.top();
        pq.pop();
        int h=tmp[0],x=tmp[1],y=tmp[2];
        now=max(now,h);
        ++ans[now];
        for(int i=0;i<4;++i){
            int xx=dx[i]+x,yy=dy[i]+y;
            if(xx<1||xx>n||yy<1||yy>m||vis[xx][yy]) continue;
            pq.push({a[xx][yy],xx,yy});
            vis[xx][yy]=1;
        }
    }
    for(int i=1;i<=k;++i){
        ans[i]+=ans[i-1];
        cout<<n*m-ans[i]<<endl;
    }
    return 0;
}
2024/8/4 23:04
加载中...