1. 程式人生 > >Forgery(CodeForces 1059B)

Forgery(CodeForces 1059B)

Description

Student Andrey has been skipping physical education lessons for the whole term, and now he must somehow get a passing grade on this subject. Obviously, it is impossible to do this by legal means, but Andrey doesn't give up. Having obtained an empty certificate from a local hospital, he is going to use his knowledge of local doctor's handwriting to make a counterfeit certificate of illness. However, after writing most of the certificate, Andrey suddenly discovered that doctor's signature is impossible to forge. Or is it?

For simplicity, the signature is represented as an n×m grid, where every cell is either filled with ink or empty. Andrey's pen can fill a 3×3 square without its central cell if it is completely contained inside the grid, as shown below.

xxx
x.x
xxx

Determine whether is it possible to forge the signature on an empty n×mn×m grid.

Input

The first line of input contains two integers nn and mm (3≤n,m≤1000).

Then nn lines follow, each contains mm characters. Each of the characters is either '.', representing an empty cell, or '#', representing an ink filled cell.

Output

If Andrey can forge the signature, output "YES". Otherwise output "NO".

You can print each letter in any case (upper or lower).

Sample Input

Input

3 3
###
#.#
###

Output

YES

Input

3 3
###
###
###

Output

NO

Input

4 3
###
###
###
###

Output

YES

Input

5 7
.......
.#####.
.#.#.#.
.#####.
.......

Output

YES

Hint

In the first sample Andrey can paint the border of the square with the center in (2,2).

In the second sample the signature is impossible to forge.

In the third sample Andrey can paint the borders of the squares with the centers in (2,2)and (3,2):

  1. we have a clear paper:
    ...
    ...
    ...
    ...
    
  2. use the pen with center at (2,2).
    ###
    #.#
    ###
    ...
    
  3. use the pen with center at (3,2).
    ###
    ###
    ###
    ###
    

In the fourth sample Andrey can paint the borders of the squares with the centers in (3,3) and (3,5).

題解:根據已知方陣構造一個滿足條件的方陣,對比差別。

程式碼如下:

#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<string>
#include<cmath>
#include<map>
#include<stack>
#include<vector>
#include<queue>
#include<set>
#include<algorithm>
#define max(a,b)   (a>b?a:b)
#define min(a,b)   (a<b?a:b)
#define swap(a,b)  (a=a+b,b=a-b,a=a-b)
#define maxn 320007
#define N 100000000
#define INF 0x3f3f3f3f
#define mod 1000000009
#define e  2.718281828459045
#define eps 1.0e18
#define PI acos(-1)
#define lowbit(x) (x&(-x))
#define read(x) scanf("%d",&x)
#define put(x) printf("%d\n",x)
#define memset(x,y) memset(x,y,sizeof(x))
#define Debug(x) cout<<x<<" "<<endl
#define lson i << 1,l,m
#define rson i << 1 | 1,m + 1,r
#define ll long long
//std::ios::sync_with_stdio(false);
//cin.tie(NULL);
using namespace std;


char a[1111][1111],b[1111][1111];
int main()
{
    memset(a,'.');
    memset(b,'.');
    int n,m;
    cin>>n>>m;
    int l,r;
    for(int i=0; i<n; i++)
        for(int j=0; j<m; j++)
        {
            cin>>a[i][j];
        }
    for(int i=0; i<n-2; i++)
        for(int j=0; j<m-2; j++)
        {
            if(a[i][j]=='#'&&a[i][j+1]=='#'&&a[i][j+2]=='#'&&a[i+1][j]=='#'&&a[i+2][j]=='#'&&a[i+1][j+2]=='#'&&a[i+2][j+1]=='#'&&a[i+2][j+2]=='#')
                b[i][j]='#',b[i][j+1]='#',b[i][j+2]='#',b[i+1][j]='#',b[i+2][j]='#',b[i+1][j+2]='#',b[i+2][j+1]='#',b[i+2][j+2]='#';
        }
    for(int i=0; i<n; i++)
        for(int j=0; j<m; j++)
            if(a[i][j]!=b[i][j])
            {
                //cout<<i<<j<<endl;
                cout<<"NO"<<endl;
                return 0;
            }
    cout<<"YES"<<endl;
    return 0;
}