Problem:
Score: 300 points

Problem Statement

We have a canvas divided into a grid with H rows and W columns. The square at the i-th row from the top and the j-th column from the left is represented as (i, j).

Initially, all the squares are white. square1001 wants to draw a picture with black paint. His specific objective is to make Square (i, j) black when s_{i, j}= #, and to make Square (i, j) white when s_{i, j}= ..

However, since he is not a good painter, he can only choose two squares that are horizontally or vertically adjacent and paint those squares black, for some number of times (possibly zero). He may choose squares that are already painted black, in which case the color of those squares remain black.

Determine if square1001 can achieve his objective.

Constraints

H is an integer between 1 and 50 (inclusive).

W is an integer between 1 and 50 (inclusive).

For every (i, j) (1 \leq i \leq H, 1 \leq j \leq W), s_{i, j} is # or ..

Input

Input is given from Standard Input in the following format:

H W
s_{1, 1} s_{1, 2} s_{1, 3} ... s_{1, W}
s_{2, 1} s_{2, 2} s_{2, 3} ... s_{2, W}
: :
s_{H, 1} s_{H, 2} s_{H, 3} ... s_{H, W}

Output

If square1001 can achieve his objective, print Yes; if he cannot, print No.

Sample Input 1

3 3
.#.
###
.#.

Sample Output 1

Yes

One possible way to achieve the objective is shown in the figure below. Here, the squares being painted are marked by stars.

Sample Input 2

5 5
#.#.#
.#.#.
#.#.#
.#.#.
#.#.#

Sample Output 2

No

square1001 cannot achieve his objective here.

Sample Input 3

11 11
...#####...
.##.....##.
#..##.##..#
#..##.##..#
#.........#
#...###...#
.#########.
.#.#.#.#.#.
##.#.#.#.##
..##.#.##..
.##..#..##.

Sample Output 3

Yes

Solution in Rust (1.15.1) (judge verdict: Accepted)

macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

#[allow(dead_code)]
fn npop(v: &mut Vec<char>, n: i32) -> Result<String, String> {
    let mut res: Vec<char> = Vec::new();
    for _ in 0..n {
        let c = v.pop().ok_or("".to_string())?;
        res.push(c);
    }
    res.reverse();
    let ret: String = res.iter().map(|c| *c).collect();
    return Ok(ret);
}

#[allow(dead_code)]
fn nget(v: &Vec<char>, n: i32) -> Result<String, String> {
    let mut tmp_v = v.clone();
    let res = npop(&mut tmp_v, n)?;
    return Ok(res);
}

#[allow(dead_code)]
fn is_valid_range(v: &Vec<char>, idx_a: i32, idx_b: i32) -> bool {
    let mut can = true;
    if idx_a < 0 {
        can = false;
    }
    let v_len = v.len() as i32;
    if v_len < idx_b {
        can = false;
    }
    return can;
}

#[allow(dead_code)]
fn get_range(v: &Vec<char>, idx_a: i32, idx_b: i32) -> Result<String, String> {
    if ! is_valid_range(v, idx_a, idx_b) {
        return Err("".to_string());
    }
    let mut res = String::new();
    for (i,c) in v.iter().enumerate() {
        let i = i as i32;
        if i < idx_a {
            continue;
        }
        if idx_b <= i {
            break;
        }
        res.push(*c);
    }
    return Ok(res);
}

#[allow(dead_code)]
fn pop_range(v: &mut Vec<char>, idx_a: i32, idx_b: i32) -> Result<String, String> {
    if ! is_valid_range(v, idx_a, idx_b) {
        return Err("".to_string());
    }
    let mut res = String::new();
    let mut pop_idxs: Vec<i32> = Vec::new();
    for (i,c) in v.iter().enumerate() {
        let i = i as i32;
        if i < idx_a {
            continue;
        }
        if idx_b <= i {
            break;
        }
        res.push(*c);
        pop_idxs.push(i);
    }
    for _ in 0..pop_idxs.len() {
        match pop_idxs.pop() {
            Some(idx) => {
                v.remove(idx as usize);
            },
            None => {}
        }
    }
    return Ok(res);
}

fn main() {
    input!{
        h: i32,
        w: i32,
        vv: [chars; h]
    }
    let _ = w;
    let mut can_all = true;
    let mut can_partial: bool;
    for i in 0..vv.len() {
        for j in 0..vv[i].len() {
            can_partial = false;
            if vv[i][j] == '#' {
                if j > 0 && vv[i][j-1] == '#' {
                    can_partial = true;
                } else if j < vv[i].len()-1 && vv[i][j+1] == '#' {
                    can_partial = true;
                } else if i < vv.len()-1 && vv[i+1][j] == '#' {
                    can_partial = true;
                } else if i > 0 && vv[i-1][j] == '#' {
                    can_partial = true;
                }
                if ! can_partial {
                    can_all = false;
                    break;
                }
            }
        }
        if ! can_all {
            break;
        }
    }
    if can_all {
        println!("Yes");
    } else {
        println!("No");
    }
}