Advertisement
Ankit_132

B

Apr 27th, 2024
893
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.12 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int main(){
  5.     int tst;
  6.     cin>>tst;
  7.     while(tst--){
  8.         int n, m;
  9.         cin >> n >> m;
  10.         string s[n];
  11.      
  12.         for (int i = 0; i < n; i++)        cin >> s[i];
  13.    
  14.         int f = 0;
  15.        
  16.         for (char x : {'B', 'W'})
  17.         {
  18.             int row_max = 0, col_max = 0, row_min = 1e9, col_min = 1e9;
  19.    
  20.             for (int i = 0; i < n; i++)
  21.             {
  22.                 for (int j = 0; j < m; j++)
  23.                 {
  24.                     if (s[i][j] == x)
  25.                     {
  26.                         row_max = max(row_max, i);
  27.                         row_min = min(row_min, i);
  28.                         col_max = max(col_max, j);
  29.                         col_min = min(col_min, j);
  30.                     }
  31.                 }
  32.             }
  33.            
  34.             if (col_min == 0 && col_max == m-1 && row_min == 0 && row_max == n-1)
  35.             {
  36.                 cout << "YES" << endl;
  37.                 f = 1;
  38.                 break;
  39.             }
  40.         }
  41.        
  42.         if(!f)
  43.             cout << "NO" << endl;
  44.     }
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement