Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- using namespace std;
- int main(){
- int tst;
- cin>>tst;
- while(tst--){
- int n, m;
- cin >> n >> m;
- string s[n];
- for (int i = 0; i < n; i++) cin >> s[i];
- int f = 0;
- for (char x : {'B', 'W'})
- {
- int row_max = 0, col_max = 0, row_min = 1e9, col_min = 1e9;
- for (int i = 0; i < n; i++)
- {
- for (int j = 0; j < m; j++)
- {
- if (s[i][j] == x)
- {
- row_max = max(row_max, i);
- row_min = min(row_min, i);
- col_max = max(col_max, j);
- col_min = min(col_min, j);
- }
- }
- }
- if (col_min == 0 && col_max == m-1 && row_min == 0 && row_max == n-1)
- {
- cout << "YES" << endl;
- f = 1;
- break;
- }
- }
- if(!f)
- cout << "NO" << endl;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement