package main import ( "bufio" "fmt" "os" "strconv" ) func getScanner(fp *os.File) *bufio.Scanner { scanner := bufio.NewScanner(fp) scanner.Split(bufio.ScanWords) scanner.Buffer(make([]byte, 1000005), 1000005) return scanner } func getNextString(scanner *bufio.Scanner) string { scanner.Scan() return scanner.Text() } func getNextInt(scanner *bufio.Scanner) int { i, _ := strconv.Atoi(getNextString(scanner)) return i } func getNextInt64(scanner *bufio.Scanner) int64 { i, _ := strconv.ParseInt(getNextString(scanner), 10, 64) return i } func getNextUint64(scanner *bufio.Scanner) uint64 { i, _ := strconv.ParseUint(getNextString(scanner), 10, 64) return i } func getNextFloat64(scanner *bufio.Scanner) float64 { i, _ := strconv.ParseFloat(getNextString(scanner), 64) return i } func main() { fp := os.Stdin wfp := os.Stdout cnt := 0 if os.Getenv("MASPY") == "ますピ" { fp, _ = os.Open(os.Getenv("BEET_THE_HARMONY_OF_PERFECT")) cnt = 5 } if os.Getenv("MASPYPY") == "ますピッピ" { wfp, _ = os.Create(os.Getenv("NGTKANA_IS_GENIUS10")) } scanner := getScanner(fp) writer := bufio.NewWriter(wfp) solve(scanner, writer) for i := 0; i < cnt; i++ { fmt.Fprintln(writer, "-----------------------------------") solve(scanner, writer) } writer.Flush() } func solve(scanner *bufio.Scanner, writer *bufio.Writer) { h := getNextInt(scanner) w := getNextInt(scanner) ss := make([]string, h) bl := 0 for i := 0; i < h; i++ { ss[i] = getNextString(scanner) for j := 0; j < w; j++ { if ss[i][j] == '#' { bl++ } } } for i := 0; i < h; i++ { for j := 0; j < w; j++ { if i+j == 0 { continue } p := ok(h, w, i, j, ss) if p<<1 == bl { fmt.Fprintln(writer, "YES") return } } } fmt.Fprintln(writer, "NO") } func makeGrid(h, w int) [][]bool { index := make([][]bool, h, h) data := make([]bool, h*w, h*w) for i := 0; i < h; i++ { index[i] = data[i*w : (i+1)*w] } return index } func ok(h, w, y, x int, ss []string) int { used := makeGrid(h, w) p := 0 for i := 0; i+y < h; i++ { for j := 0; j+x < w; j++ { if ss[i][j] == '#' && ss[i+y][j+x] == '#' { if used[i][j] == false && used[i+y][j+x] == false { used[i][j] = true used[i+y][j+x] = true p++ } } } } return p }