Codeforces Round #472 B. Mystical Mosaic

4384 단어 codeforces
B. Mystical Mosaic There is a rectangular grid of n rows of m initially-white cells each.
Arkady performed a certain number (possibly zero) of operations on it. In the i-th operation, a non-empty subset of rows Ri and a non-empty subset of columns Ci are chosen. For each row r in Ri and each column c in Ci, the intersection of row r and column c is coloured black.
There’s another constraint: a row or a column can only be chosen at most once among all operations. In other words, it means that no pair of (i, j) (i 
You are to determine whether a valid sequence of operations exists that produces a given final grid.
Input The first line contains two space-separated integers n and m (1 ≤ n, m ≤ 50) — the number of rows and columns of the grid, respectively.
Each of the following n lines contains a string of m characters, each being either ‘.’ (denoting a white cell) or ‘#’ (denoting a black cell), representing the desired setup.
Output If the given grid can be achieved by any valid sequence of operations, output “Yes”; otherwise output “No” (both without quotes).
You can print each character in any case (upper or lower).
Examples inputCopy 5 8 .#.#..#. …..#.. .#.#..#.
.#….
…..#.. output Yes inputCopy 5 5 ..#.. ..#..
#
..#.. ..#.. output No inputCopy 5 9 ……..#
……..
..##.#… …….#. ….#.#.# output No Note For the first example, the desired setup can be produced by 3 operations, as is shown below.
For the second example, the desired setup cannot be produced, since in order to colour the center row, the third row and all columns must be selected in one operation, but after that no column can be selected again, hence it won’t be possible to colour the other cells in the center column.
제목: 초기 행렬은 모두'.'이고,각 행과 각 열은 교차 작업을 수행할 수 있으며, 교차 작업 후에는 행의 열이 교차하는 메쉬를 "#"으로 설정하여 각 행마다 한 번만 수행할 수 있도록 제한된 작업 후에 지정된 행렬을 얻을 수 있는지 확인합니다.
사고방식: 같은 줄의'#'을 폭력적으로 검사하고 있는 줄이 같은지 아닌지
코드:
#include
#include
#include
using namespace std;
typedef long long ll;
string str[105];
    int n,m;
bool ck(int i,int j){
    for(int x=0;xif(str[x][j]=='#'){
            if(str[x]!=str[i])
            return 0;
        }
    }
    return 1;
}
int main(){
cin>>n>>m;
    for(int i=0;icin>>str[i];
    }
    int len=str[0].length();

    for(int i=0;ifor(int j=0;jif(str[i][j]=='#'){
                if(!ck(i,j)){
                    cout<<"No"<return 0;
                }
            }
        }

    }

    cout<<"Yes"<return 0;
}

좋은 웹페이지 즐겨찾기