use std::{convert::TryInto, io::stdin}; fn main() { let (h, w) = { let mut buf = String::new(); stdin().read_line(&mut buf).unwrap(); let mut h_and_w = buf.split_whitespace().map(|s| s.parse::().unwrap()); (h_and_w.next().unwrap(), h_and_w.next().unwrap()) }; let ss: Vec> = { (1..=h) .map(|_i| { let mut buf = String::new(); stdin().read_line(&mut buf).unwrap(); buf.trim_end().chars().map(|c| c.into()).collect() }) .collect() }; println!("{}", solve(h, w, ss)); } fn solve(h: u8, w: u8, ss: Vec>) -> &'static str { if any_overlap(h, w, ss) { "YES" } else { "NO" } } fn any_overlap(h: u8, w: u8, ss: Vec>) -> bool { for vec_row in 0..(h as i8) { for vec_col in (-(w as i8) + 1)..(w as i8) { if is_overlap(vec_row, vec_col, h, w, ss.clone()) { return true; } } } false } fn is_overlap(vec_row: i8, vec_col: i8, h: u8, w: u8, ss: Vec>) -> bool { if vec_row == 0 && vec_col == 0 { return false; } let mut ss = ss; for src_row in 0..h { for src_col in 0..w { let src_row = src_row as usize; let src_col = src_col as usize; if let Square::Black = ss[src_row][src_col] { let dst_row = (src_row as i8) + vec_row; let dst_col = (src_col as i8) + vec_col; if !in_rect(dst_row, dst_col, h, w) { return false; } let dst_row = dst_row as usize; let dst_col = dst_col as usize; if let Square::Black = ss[dst_row][dst_col] { ss[src_row][src_col] = Square::White; ss[dst_row][dst_col] = Square::White; } } } } all_black(ss) } fn in_rect(row: i8, col: i8, h: u8, w: u8) -> bool { row >= 0 && row <= (h - 1).try_into().unwrap() && col >= 0 && col <= (w - 1).try_into().unwrap() } fn all_black(ss: Vec>) -> bool { ss.iter() .all(|row| row.iter().all(|&col| col == Square::White)) } #[derive(PartialEq, Copy, Clone, Debug)] enum Square { White, Black, } impl From for Square { fn from(c: char) -> Self { match c { '#' => Self::Black, '.' => Self::White, _ => unreachable!(), } } }