#include using namespace std; #define ll long long int #define ull unsigned long long int #define uint unsigned int #define read(n) scanf("%d",&n) #define readll(n) scanf("%lld",&n) #define read2(n,m) scanf("%d%d",&n,&m) #define read3(n,m,l) scanf("%d%d%d",&n,&m,&l) #define fr(i,n) for(int i=0;i=0;i--) #define init(mem,v) memset(mem,v,sizeof(mem)) #define DB(x) cout<<__LINE__<<" :: "<<#x<< ": "< pii; typedef pair ppi; #define inf 2000000000 const int mx=1005; char mp[mx][mx]; bool vis[mx][mx]; int dp[mx][mx][4]; int n,m; // largest rectangle that encloses these two points ppi largest(ppi a,ppi b){ a.first.first=min(a.first.first,b.first.first); a.first.second=min(a.first.second,b.first.second); a.second.first=max(a.second.first,b.second.first); a.second.second=max(a.second.second,b.second.second); return a; } // top-left, bottom-right ppi flood_fill(int i,int j){ if(i < 0 or j < 0 or i >= n or j >= m or mp[i][j] == 'B' or vis[i][j]) return ppi(pii(inf,inf),pii(-inf,-inf)); vis[i][j]=true; ppi ret=ppi(pii(i,j),pii(i,j)); ret=largest(ret,flood_fill(i+1,j)); ret=largest(ret,flood_fill(i-1,j)); ret=largest(ret,flood_fill(i,j+1)); ret=largest(ret,flood_fill(i,j-1)); return ret; } #define get_dp(i,j,k) ((i>=0 and j>=0 and i=0;j--){ dp[i][j][1]+=get_dp(i-1,j,1)+get_dp(i,j+1,1)-get_dp(i-1,j+1,1); } for(int i=n-1;i>=0;i--) for(int j=0;j=0;i--) for(int j=m-1;j>=0;j--){ dp[i][j][3]+=get_dp(i+1,j,3)+get_dp(i,j+1,3)-get_dp(i+1,j+1,3); } bool poss=false; fr(i,n) fr(j,m){ bool ok=true; if(i>0 and j>0 and dp[i-1][j-1][0]>0) ok=false; if(i>0 and j0) ok=false; if(i0 and dp[i+1][j-1][2]>0) ok=false; if(i0) ok=false; if(ok) poss=true; } if(poss) printf("YES\n"); else printf("NO\n"); } }