Algorithm


B. Mystical Mosaic
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

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 < j) exists such that  or , where  denotes intersection of sets, and  denotes the empty set.

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
input
Copy
5 8
.#.#..#.
.....#..
.#.#..#.
#.#....#
.....#..
output
Copy
Yes
input
Copy
5 5
..#..
..#..
#####
..#..
..#..
output
Copy
No
input
Copy
5 9
........#
#........
..##.#...
.......#.
....#.#.#
output
Copy
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.

 



 

Code Examples

#1 Code Example with C++ Programming

Code - C++ Programming

#include <bits/stdc++.h>

using namespace std;

int n, m;
vector<string> g;

int main() {
  scanf("%d %d", &n, &m);
  for(int i = 0; i < n; ++i) {
    string s;
    cin >> s;
    g.push_back(s);
  }

  for(int i = 0; i < n; ++i)
    for(int j = 0; j < m; ++j)
      if(g[i][j] == '#')
        for(int k = 0; k < n; ++k)
          if(g[k][j] == '#' && g[i] != g[k]) {
            puts("No");
            return 0;
          }

  cout << "Yes" << endl;

  return 0;
}
Copy The Code & Try With Live Editor

Input

x
+
cmd
5 8
.#.#..#.
.....#..
.#.#..#.
#.#....#
.....#..

Output

x
+
cmd
yes
Advertisements

Demonstration


Codeforces Solution-Mystical Mosaic-Solution in C, C++, Java, Python

Previous
Codeforces solution 1080-B-B. Margarite and the best present codeforces solution
Next
CodeChef solution DETSCORE - Determine the Score CodeChef solution C,C+