Codeforces Round #514 (Div. 2) B.Forgery

描述

传送门:我是传送门

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×mn×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.

1
2
3
xxx
x.x
xxx

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

输入

The first line of input contains two integers $n$ and $m$ ($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.

输出

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

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

样例

输入

1
2
3
4
3 3
###
#.#
###

输出

YES

输入

1
2
3
4
3 3
###
###
###

输出

NO

输入

1
2
3
4
5
4 3
###
###
###
###

输出

YES

输入

1
2
3
4
5
6
5 7
.......
.#####.
.#.#.#.
.#####.
.......

输出

YES

Note

>

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:
1
2
3
4
...
...
...
...
  1. use the pen with center at (2,2)(2,2).
1
2
3
4
###
#.#
###
...
  1. use the pen with center at (3,2)(3,2).
1
2
3
4
###
###
###
###

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

思路

先扫一遍,不必管3x3小格子的中间位置是否空着,只要符合周围8个为’#’便在另一个数组总模拟的“盖章”;

最后对比一下新旧数组是否一致变好了

也不知道自己昨晚是怎么回事,傻逼了,div.2第二题都写不出来了。以后cf还是要常打,这种题目要多练练。

ps:刚发现cf对’YES’跟’Yes’是不加区分的

下边的代码也能过

代码

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#include <bits/stdc++.h>
using namespace std;
const int N = 1e3+10;
int n,m;
char a[N][N];
char t[N][N];
int tx[] = {-1,-1,-1,0,0,1,1,1};
int ty[] = {-1,0,1,-1,1,-1,0,1};
int main()
{
#ifdef ONLINE_JUDGE
#else
freopen("in.txt","r",stdin);
// freopen("out.txt","w",stdout);
#endif
scanf("%d %d",&n,&m);
for(int i = 1;i <= n;i++) scanf("%s",a[i]+1);
memset(t,'.',sizeof t);
for(int i = 2;i < n;i++)
for(int j = 2;j < m;j++)
{
bool flag = 1;
for(int k = 0;k < 8;k++)
{
if(a[i+tx[k]][j+ty[k]] != '#')
{
flag = 0;
break;
}
}
if(flag)
{
for(int k = 0;k < 8;k++)
t[i+tx[k]][j+ty[k]] = '#';
}
}
for(int i = 1;i <= n;i++)
{
for(int j = 1;j <= m;j++)
{
if(a[i][j] != t[i][j])
{
printf("No\n");
return 0;
}
}
}
printf("Yes\n");
fclose(stdin);
// fclose(stdout);
return 0;
}