C++20编译失败,17编译正常
查看原帖
C++20编译失败,17编译正常
1020359
29431_com楼主2024/6/27 23:40

代码长这样,有大佬能告诉为什么吗,以后避免一下

#include<bits/stdc++.h>
#define VVI vector<vector<int>>
#define VI vector<int>
using namespace std;
using ll = long long;
int n,m;
int A[550][550];
VVI l(550,VI(550,0x3f3f3f3f));
VVI r(550,VI(550,-1));
VVI vis(550,VI(550,0));
int fx[4]={0,1,0,-1};
int fy[4]={1,0,-1,0};
void dfs(int x,int y)
{
    vis[x][y] = 1; int nx,ny;
    for(int i = 0 ; i < 4 ;i++){
        nx=x+fx[i];ny=y+fy[i];
        //if(nx==n&&ny==3)cout<<x<<" tt "<< y<<endl;
        if(!(nx>0&&nx<=n&&ny>0&&ny<=m)||A[nx][ny]>=A[x][y])continue;
        if(!vis[nx][ny]){dfs(nx,ny);}
        l[x][y]=min(l[x][y],l[nx][ny]); r[x][y]=max(r[x][y],r[nx][ny]);
    }
}
int main()
{
    cin>>n>>m;
    for(int i = 1 ; i <= n ; i++ )
        for(int j = 1 ; j <= m ;j++)
            cin>>A[i][j];
    for(int i = 1 ; i <= m ; i++)l[n][i]=r[n][i]=i;
    for(int i = 1 ; i <= m ;i++)dfs(1,i);
    int cnt = 0; 
    for(int i = 1 ; i <= m ; i++)
        if(!vis[n][i])
            {cnt++;
            /* cout<<i<<endl; */};
    if(cnt!=0){cout<< 0 <<endl<< cnt;return 0;}
    int maxr = 0; int nowr = 0; cnt = 0;
    for(int i = 1 ; i <= m ; i++){
        if(l[1][i]<=nowr+1)maxr=max(maxr,r[1][i]);
        else if(l[1][i]==0x3f3f3f3f){}
        else{nowr = maxr;i--;cnt++;}
    }
    if(maxr != nowr)cnt++;
    cout<<1<<endl<<cnt;
    return 0;
}

/*
2 5
9 1 5 4 3
8 7 6 1 2

3 6
8 4 5 6 4 4
7 3 4 3 3 3
3 2 2 1 1 2

*/
2024/6/27 23:40
加载中...