#include <iostream>                                                    
#include <array>                                                       
                                                                       
int main()                                                             
{                                                                      
    int H, W;                                                          
    std::array<std::array<bool, 50>, 50> s{};                          
    std::cin >> H >> W;                                                
    for (int h = 0; h < H; h++) {                                      
        for (int w = 0; w < W; w++) {                                  
            char c;                                                    
            std::cin >> c;                                             
            if (c == '#') {                                            
                s.at(h).at(w) = 1;                                     
            } else {                                                   
                s.at(h).at(w) = 0;                                     
            }                                                          
        }                                                              
    }                                                                  
    for (int h = 0; h < H; h++) {                                      
        for (int w = 0; w < W; w++) {                                  
            if (s[h][w] == 0) {                                        
                continue;                                              
            }                                                          
            bool flag = true;                                          
            for (int i = -1; i <= 1; i++) {                            
                for (int j = -1; j <= 1; j++) {                        
                    if ((i == 0) ^ (j == 0)) {                         
                        try {                                          
                            flag = flag && s.at(h + i).at(w + j) == 0; 
                        } catch (...) {                                
                        }                                              
                    }                                                  
                }                                                      
            }                                                          
            if (flag) {                                                
                std::cout << "No" << std::endl;                        
                return 0;                                              
            }                                                          
        }                                                              
    }                                                                  
    std::cout << "Yes" << std::endl;                                   
                                                                       
    return 0;                                                          
}                                                                      


Measured memory_bytes: 384