Problem:


Score: 300 points

Problem Statement

We have a canvas divided into a grid with H rows and W columns. The square at the i-th row from the top and the j-th column from the left is represented as (i, j).

Initially, all the squares are white. square1001 wants to draw a picture with black paint. His specific objective is to make Square (i, j) black when s_{i, j}= #, and to make Square (i, j) white when s_{i, j}= ..

However, since he is not a good painter, he can only choose two squares that are horizontally or vertically adjacent and paint those squares black, for some number of times (possibly zero). He may choose squares that are already painted black, in which case the color of those squares remain black.

Determine if square1001 can achieve his objective.  

Constraints

H is an integer between 1 and 50 (inclusive).

W is an integer between 1 and 50 (inclusive).

For every (i, j) (1 \leq i \leq H, 1 \leq j \leq W), s_{i, j} is # or ..

Input

Input is given from Standard Input in the following format:

H W
s_{1, 1} s_{1, 2} s_{1, 3} ... s_{1, W}
s_{2, 1} s_{2, 2} s_{2, 3} ... s_{2, W}
  :   :
s_{H, 1} s_{H, 2} s_{H, 3} ... s_{H, W}

Output

If square1001 can achieve his objective, print Yes; if he cannot, print No.

Sample Input 1

3 3
.#.
###
.#.

Sample Output 1

Yes

One possible way to achieve the objective is shown in the figure below. Here, the squares being painted are marked by stars.

Sample Input 2

5 5
#.#.#
.#.#.
#.#.#
.#.#.
#.#.#

Sample Output 2

No

square1001 cannot achieve his objective here.

Sample Input 3

11 11
...#####...
.##.....##.
#..##.##..#
#..##.##..#
#.........#
#...###...#
.#########.
.#.#.#.#.#.
##.#.#.#.##
..##.#.##..
.##..#..##.

Sample Output 3

Yes



Sample input:
3 3
.#.
###
.#.


Sample output:
Yes

Submission status: Runtime Error

Solution code:
a,b = map(int,input().split())
c=[list(map(str,list(input()))) for i in range(b)]
#c = list(map(str,input().split()))
# for i in range(len(a)+2):
#     c.insert()
#c[Y][X]
x=a
y=b
e=0
r=0
if y>1 or x>1:
    for i in range(0,y,2):
        for j in range(1,x,2):

            if c[i][j] == "#":
                e+=2
                if i > 0 and i < x-1 and j >0 and j < y-1:
                    if c[i+1][j]=="#" or c[i][j+1]=="#" or c[i-1][j]=="#" or c[i][j-1]=="#" :
                        r+=2

                elif i==0 and j!= 0 and j != y-1 :
                    if c[i+1][j]=="#" or c[i][j+1]=="#" or c[i][j-1]=="#" :
                        r+=2

                elif i == x-1 and j != 0 and j != y-1 :
                    if c[i][j+1] == "#" or c[i-1][j] == "#" or c[i][j-1] == "#" :
                        r+=2

                elif j == 0 and i != 0 and i != y-1:
                    if c[i+1][j] == "#" or c[i][j+1] == "#" or c[i-1][j] == "#" :
                        r+=2

                elif j == y-1 and i != y-1 and i != 0:
                    if c[i+1][j] == "#" or c[i-1][j] == "#" or c[i][j-1] == "#" :
                        r+=2

                elif i==0 and j == 0:
                    if c[i+1][j]=="#" or c[i][j+1]=="#" :
                        r+=2

                elif i==0 and j == y-1:
                    if c[i+1][j]=="#"  or c[i][j-1]=="#" :
                        r+=2

                elif i==x-1 and j == 0:
                    if c[i][j+1]=="#" or c[i-1][j]=="#" :
                        r+=2

                elif i == x-1 and j == y-1:
                    if c[i-1][j]=="#" or c[i][j-1]=="#" :
                        r+=2
elif y==1 :
    for i in range(0,x,2):
        if c[0][i] == "#":
            e+=2
            if i < x-1 :
                if c[0][i+1]=="#" :
                    r+=2
elif x==1 :
    for i in range(0,y,2):
        if c[i][0] == "#":
            e+=2
            if i < y-1 :
                if c[i+1][0]=="#" :
                    r+=2
if r==e and r!=0:
    print("Yes")
else :
    print("No")

Submission status: Runtime Error

Solution code:
a,b = map(int,input().split())
c=[list(map(str,list(input()))) for i in range(b)]
x=a
y=b
e=0
r=0
if y>1 or x>1:
    for i in range(0,y,2):
        for j in range(1,x,2):

            if c[i][j] == "#":
                e+=2
                if i > 0 and i < x-1 and j >0 and j < y-1:
                    if c[i+1][j]=="#" or c[i][j+1]=="#" or c[i-1][j]=="#" or c[i][j-1]=="#" :
                        r+=2

                elif i==0 and j!= 0 and j != y-1 :
                    if c[i+1][j]=="#" or c[i][j+1]=="#" or c[i][j-1]=="#" :
                        r+=2

                elif i == x-1 and j != 0 and j != y-1 :
                    if c[i][j+1] == "#" or c[i-1][j] == "#" or c[i][j-1] == "#" :
                        r+=2

                elif j == 0 and i != 0 and i != y-1:
                    if c[i+1][j] == "#" or c[i][j+1] == "#" or c[i-1][j] == "#" :
                        r+=2

                elif j == y-1 and i != y-1 and i != 0:
                    if c[i+1][j] == "#" or c[i-1][j] == "#" or c[i][j-1] == "#" :
                        r+=2

                elif i==0 and j == 0:
                    if c[i+1][j]=="#" or c[i][j+1]=="#" :
                        r+=1

                elif i==0 and j == y-1:
                    if c[i+1][j]=="#"  or c[i][j-1]=="#" :
                        r+=2

                elif i==x-1 and j == 0:
                    if c[i][j+1]=="#" or c[i-1][j]=="#" :
                        r+=2

                elif i == x-1 and j == y-1:
                    if c[i-1][j]=="#" or c[i][j-1]=="#" :
                        r+=2
elif y==1 :
    for i in range(0,x,2):
        if c[0][i] == "#":
            e+=2
            if i < x-1 :
                if c[0][i+1]=="#" :
                    r+=2
elif x==1 :
    for i in range(0,y,2):
        if c[i][0] == "#":
            e+=2
            if i < y-1 :
                if c[i+1][0]=="#" :
                    r+=2
if r==e and r!=0:
    print("Yes")
else :
    print("No")

Submission status: Runtime Error

Solution code:
a,b = map(int,input().split())
c=[list(map(str,list(input()))) for i in range(b)]
x=a
y=b
e=0
r=0
if y>1 or x>1:
    for i in range(0,y,2):
        for j in range(1,x,2):

            if c[i][j] == "#":
                e+=2
                if i > 0 and i < x-1 and j >0 and j < y-1:
                    if c[i+1][j]=="#" or c[i][j+1]=="#" or c[i-1][j]=="#" or c[i][j-1]=="#" :
                        r+=2

                elif i==0 and j!= 0 and j != y-1 :
                    if c[i+1][j]=="#" or c[i][j+1]=="#" or c[i][j-1]=="#" :
                        r+=2

                elif i == x-1 and j != 0 and j != y-1 :
                    if c[i][j+1] == "#" or c[i-1][j] == "#" or c[i][j-1] == "#" :
                        r+=2

                elif j == 0 and i != 0 and i != y-1:
                    if c[i+1][j] == "#" or c[i][j+1] == "#" or c[i-1][j] == "#" :
                        r+=2

                elif j == y-1 and i != y-1 and i != 0:
                    if c[i+1][j] == "#" or c[i-1][j] == "#" or c[i][j-1] == "#" :
                        r+=2

                elif i==0 and j == 0:
                    if c[i+1][j]=="#" or c[i][j+1]=="#" :
                        r+=1

                elif i==0 and j == y-1:
                    if c[i+1][j]=="#"  or c[i][j-1]=="#" :
                        r+=2

                elif i==x-1 and j == 0:
                    if c[i][j+1]=="#" or c[i-1][j]=="#" :
                        r+=2

                elif i == x-1 and j == y-1:
                    if c[i-1][j]=="#" or c[i][j-1]=="#" :
                        r+=2
elif y==1 :
    for i in range(0,x,2):
        if c[0][i] == "#":
            e+=2
            print(i)
            if i < x-1 :
                if c[0][i+1]=="#" :
                    r+=2
elif x==1 :
    for i in range(0,y,2):
        if c[i][0] == "#":
            e+=2
            if i < y-1 :
                if c[i+1][0]=="#" :
                    r+=2
if r==e and r!=0:
    print("Yes")
else :
    print("No")

Submission status: Runtime Error

Solution code:
a,b = map(int,input().split())
c=[list(map(str,list(input()))) for i in range(b)]
#c = list(map(str,input().split()))
# for i in range(len(a)+2):
#     c.insert()
#c[Y][X]
x=a
y=b
e=0
r=0
if y>1 and x>1:
    for i in range(0,y,2):
        for j in range(1,x,2):

            if c[i][j] == "#":
                e+=2
                if i > 0 and i < x-1 and j >0 and j < y-1:
                    if c[i+1][j]=="#" or c[i][j+1]=="#" or c[i-1][j]=="#" or c[i][j-1]=="#" :
                        r+=2

                elif i==0 and j!= 0 and j != y-1 :
                    if c[i+1][j]=="#" or c[i][j+1]=="#" or c[i][j-1]=="#" :
                        r+=2

                elif i == x-1 and j != 0 and j != y-1 :
                    if c[i][j+1] == "#" or c[i-1][j] == "#" or c[i][j-1] == "#" :
                        r+=2

                elif j == 0 and i != 0 and i != y-1:
                    if c[i+1][j] == "#" or c[i][j+1] == "#" or c[i-1][j] == "#" :
                        r+=2

                elif j == y-1 and i != y-1 and i != 0:
                    if c[i+1][j] == "#" or c[i-1][j] == "#" or c[i][j-1] == "#" :
                        r+=2

                elif i==0 and j == 0:
                    if c[i+1][j]=="#" or c[i][j+1]=="#" :
                        r+=1

                elif i==0 and j == y-1:
                    if c[i+1][j]=="#"  or c[i][j-1]=="#" :
                        r+=2

                elif i==x-1 and j == 0:
                    if c[i][j+1]=="#" or c[i-1][j]=="#" :
                        r+=2

                elif i == x-1 and j == y-1:
                    if c[i-1][j]=="#" or c[i][j-1]=="#" :
                        r+=2
elif y==1 :
    for i in range(0,x,2):
        if c[0][i] == "#":
            e+=2
            print(i)
            if i < x-1 :
                if c[0][i+1]=="#" :
                    r+=2
elif x==1 :
    for i in range(0,y,2):
        if c[i][0] == "#":
            e+=2
            if i < y-1 :
                if c[i+1][0]=="#" :
                    r+=2
if r==e and r!=0:
    print("Yes")
else :
    print("No")

Submission status: Runtime Error

Solution code:
a,b = map(int,input().split())
c=[list(map(str,list(input()))) for i in range(b)]
#c = list(map(str,input().split()))
# for i in range(len(a)+2):
#     c.insert()
#c[Y][X]
x=a
y=b
e=0
r=0

for i in range(0,y,1):
    for j in range(1,x,1):
        if c[i][j] == "#":
            e+=2
            if i > 0 and i < x-1 and j >0 and j < y-1:
                if c[i+1][j]=="#" or c[i][j+1]=="#" or c[i-1][j]=="#" or c[i][j-1]=="#" :
                    r+=2

            elif i==0 and j!= 0 and j != y-1 :
                if c[i+1][j]=="#" or c[i][j+1]=="#" or c[i][j-1]=="#" :
                    r+=2

            elif i == x-1 and j != 0 and j != y-1 :
                if c[i][j+1] == "#" or c[i-1][j] == "#" or c[i][j-1] == "#" :
                    r+=2

            elif j == 0 and i != 0 and i != y-1:
                if c[i+1][j] == "#" or c[i][j+1] == "#" or c[i-1][j] == "#" :
                    r+=2

            elif j == y-1 and i != y-1 and i != 0:
                if c[i+1][j] == "#" or c[i-1][j] == "#" or c[i][j-1] == "#" :
                    r+=2

            elif i==0 and j == 0:
                if c[i+1][j]=="#" or c[i][j+1]=="#" :
                    r+=1

            elif i==0 and j == y-1:
                if c[i+1][j]=="#"  or c[i][j-1]=="#" :
                    r+=2

            elif i==x-1 and j == 0:
                if c[i][j+1]=="#" or c[i-1][j]=="#" :
                    r+=2

            elif i == x-1 and j == y-1:
                if c[i-1][j]=="#" or c[i][j-1]=="#" :
                    r+=2
if r==e and r!=0:

    print("Yes")
elif r!=e :

    print("No")

Submission status: Runtime Error

Solution code:
a,b = map(int,input().split())
c=[list(map(str,list(input()))) for i in range(b)]
#c = list(map(str,input().split()))
# for i in range(len(a)+2):
#     c.insert()
#c[Y][X]
x=a
y=b
e=0
r=0

for i in range(0,y,1):
    for j in range(1,x,1):
        if c[i][j] == "#":
            e+=2
            if i > 0 and i < x-1 and j >0 and j < y-1:
                if c[i+1][j]=="#" or c[i][j+1]=="#" or c[i-1][j]=="#" or c[i][j-1]=="#" :
                    r+=2

            elif i==0 and j!= 0 and j != y-1 :
                if c[i+1][j]=="#" or c[i][j+1]=="#" or c[i][j-1]=="#" :
                    r+=2

            elif i == x-1 and j != 0 and j != y-1 :
                if c[i][j+1] == "#" or c[i-1][j] == "#" or c[i][j-1] == "#" :
                    r+=2

            elif j == 0 and i != 0 and i != y-1:
                if c[i+1][j] == "#" or c[i][j+1] == "#" or c[i-1][j] == "#" :
                    r+=2

            elif j == y-1 and i != y-1 and i != 0:
                if c[i+1][j] == "#" or c[i-1][j] == "#" or c[i][j-1] == "#" :
                    r+=2

            elif i==0 and j == 0:
                if c[i+1][j]=="#" or c[i][j+1]=="#" :
                    r+=1

            elif i==0 and j == y-1:
                if c[i+1][j]=="#"  or c[i][j-1]=="#" :
                    r+=2

            elif i==x-1 and j == 0:
                if c[i][j+1]=="#" or c[i-1][j]=="#" :
                    r+=2

            elif i == x-1 and j == y-1:
                if c[i-1][j]=="#" or c[i][j-1]=="#" :
                    r+=2
if r==e:

    print("Yes")
else :

    print("No")

Submission status: Runtime Error

Solution code:
a,b = map(int,input().split())
c=[list(map(str,list(input()))) for i in range(b)]
#c = list(map(str,input().split()))
# for i in range(len(a)+2):
#     c.insert()
#c[Y][X]
x=a
y=b
e=0
r=0

for i in range(y):
    for j in range(x):
        if c[i][j] == "#":
            e+=1
            if i > 0 and i < x-1 and j >0 and j < y-1:
                if c[i+1][j]=="#" or c[i][j+1]=="#" or c[i-1][j]=="#" or c[i][j-1]=="#" :
                    r+=1

            elif i==0 and j!= 0 and j != y-1 :
                if c[i+1][j]=="#" or c[i][j+1]=="#" or c[i][j-1]=="#" :
                    r+=1

            elif i == x-1 and j != 0 and j != y-1 :
                if c[i][j+1] == "#" or c[i-1][j] == "#" or c[i][j-1] == "#" :
                    r+=1

            elif j == 0 and i != 0 and i != y-1:
                if c[i+1][j] == "#" or c[i][j+1] == "#" or c[i-1][j] == "#" :
                    r+=1

            elif j == y-1 and i != y-1 and i != 0:
                if c[i+1][j] == "#" or c[i-1][j] == "#" or c[i][j-1] == "#" :
                    r+=1

            elif i==0 and j == 0:
                if c[i+1][j]=="#" or c[i][j+1]=="#" :
                    r+=1

            elif i==0 and j == y-1:
                if c[i+1][j]=="#"  or c[i][j-1]=="#" :
                    r+=1

            elif i==x-1 and j == 0:
                if c[i][j+1]=="#" or c[i-1][j]=="#" :
                    r+=1

            elif i == x-1 and j == y-1:
                if c[i-1][j]=="#" or c[i][j-1]=="#" :
                    r+=1
if r==e:

    print("Yes")
else :

    print("No")

Submission status: Runtime Error

Solution code:
a,b = map(int,input().split())
c=[list(map(str,list(input()))) for i in range(b)]
#c = list(map(str,input().split()))
# for i in range(len(a)+2):
#     c.insert()
x=a
y=b
e=0
r=0
for i in range(x):
    for j in range(y):
        if c[i][j] == "#":
            e+=1
            if i > 0 and i < x-1 and j >0 and j < y-1:
                if c[i+1][j]=="#" or c[i][j+1]=="#" or c[i-1][j]=="#" or c[i][j-1]=="#" :
                    r+=1

            elif i==0 and j!= 0 and j != y<-1 :
                if c[i+1][j]=="#" or c[i][j+1]=="#" or c[i][j-1]=="#" :
                    r+=1

            elif i==x-1 and j !=0 and j!=y-1 :
                if c[i][j+1]=="#" or c[i-1][j]=="#" or c[i][j-1]=="#" :
                    r+=1

            elif j==0 and i !=0 and i !=y-1:
                if c[i+1][j]=="#" or c[i][j+1]=="#" or c[i-1][j]=="#" :
                    r+=1

            elif j==y-1 and i == y-1 and i==0:
                if c[i+1][j]=="#" or c[i-1][j]=="#" or c[i][j-1]=="#" :
                    r+=1

            elif i==0 and j == 0:
                if c[i+1][j]=="#" or c[i][j+1]=="#" :
                    r+=1

            elif i==0 and j == y<-1:
                if c[i+1][j]=="#"  or c[i][j-1]=="#" :
                    r+=1

            elif i==x-1 and j == 0:
                if c[i][j+1]=="#" or c[i-1][j]=="#" :
                    r+=1

            elif i==x-1 and j == y<-1:
                if c[i-1][j]=="#" or c[i][j-1]=="#" :
                    r+=1
if r==e:
    print("Yes")
else :
    print("No")

Submission status: Runtime Error

Solution code:
h, w = map(int, input().split())
L = ['.'*(w+1)]
for i in range(h):
  L.append('.'+input()+'.')
L.append('.'*(w+1))  

out = 1
for i in range(1, h+1):
  for j in range(1, h+1):
    if L[i][j] == '#':
      if L[i][j+1] == '#' or L[i][j-1] == '#' or L[i-1][j] == '#' or L[i+1][j] == '#':
        out *= 1
      else:
        out *= 0

if out == 1:
  print('Yes')
else:
  print('No')

Submission status: Runtime Error

Solution code:
h, w = map(int, input().split())
L = ['.'*(w+1)]
for i in range(h):
  L.append('.'+input()+'.')
L.append('.'*(w+1))  

out = 1
for i in range(1, h+1):
  for j in range(i+1, h+1):
    if L[i][j] == '#':
      if L[i][j+1] == '#' or L[i][j-1] == '#' or L[i-1][j] == '#' or L[i+1][j] == '#':
        out *= 1
      else:
        out *= 0

if out == 1:
  print('Yes')
else:
  print('No')

Submission status: Runtime Error

Solution code:
H , W = map(int,input().split())
stage = list(list(input()) for _ in range(H))

dx = [0,1,0,-1]
dy = [1,0,-1,0]
for i in range(H):
    for j in range(W):
        if stage[i][j] == ".":
            continue
        Flag = True
        for k in range(4):
            if 0 <= i + dx[k] < W and 0 <= j + dy[k] < H  and stage[i + dx[k]][j + dy[k]] == "#":
                Flag = False
                break
        if Flag:
            print("No")
            exit()
print("Yes")

Submission status: Runtime Error

Solution code:
a,b = list(map(int, input().spit()))

cs = []
cs.append("." * (b+2))
for i in range(a):
  s = "." + input() + "."
  cs.append(s)
cs.append("." * (b+2))

ans = True
for i in range(a):
  for j in range(b):
    if cs[i][j] == "#":
      if cs[i-1][j] == "." and cs[i][j-1] == "." and cs[i+1][j] == "." and cs[i][j+1] == ".":
        ans = False
        break
    if not ans:
      break
  if not ans:
    break
if ans:
  print("Yes")
else:
  print("No")

Submission status: Runtime Error

Solution code:
#include<stdio.h>
#include<stdlib.h>
#include<string.h>

#define NEW(p,n){p=malloc((n)*sizeof(p[0]));if(p==NULL){printf("not enough memory\n");exit(1);};}
//pの型の変数n個の要素分のメモリを確保し、そのアドレスをpに代入するマクロ

#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) < (b) ? (a) : (b))
#define SWAP(type, x, y) do { type tmp = x; x = y; y = tmp; } while (0)

#define MOD 1000000007 

int main(void){
    int H,W;
    scanf("%d%d",&H,&W);

    char map[H][W+1];
    for(int i=0;i<H;i++) scanf("%s",map[i]);

    for(int i=0;i<H;i++){
        for(int j=0;j<W;j++){
            int flg=0;
            if(map[i][j]=='#'){
                if(i>0 && map[i-1][j]=='#') flg=1;
                if(i<H-1 && map[i+1][j]=='#') flg=1;
                if(j>0 && map[i][j-1]=='#') flg=1;
                if(j<W-1 && map[i][j+1]=='#') flg=1;
                if(!flg){
                    printf("No\n");
                    return 0;
                }
            }
        }
    }
    
    printf("Yes\n");

    return 0;
}

Submission status: Runtime Error

Solution code:
#include<stdio.h>
#include<stdlib.h>
#include<string.h>

#define NEW(p,n){p=malloc((n)*sizeof(p[0]));if(p==NULL){printf("not enough memory\n");exit(1);};}
//pの型の変数n個の要素分のメモリを確保し、そのアドレスをpに代入するマクロ

#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) < (b) ? (a) : (b))
#define SWAP(type, x, y) do { type tmp = x; x = y; y = tmp; } while (0)

#define MOD 1000000007 

int main(void){
    int H,W;
    scanf("%d%d",&H,&W);

    char map[H][W+1];
    for(int i=0;i<H;i++) scanf("%s",map[i]);

    for(int i=0;i<H;i++){
        for(int j=0;j<W;j++){
            int flg=0;
            if(map[i][j]=='#'){
                if(i>0 && map[i-1][j]=='#') flg=1;
                if(i<H-1 && map[i+1][j]=='#') flg=1;
                if(j>0 && map[i][j-1]=='#') flg=1;
                if(j<W-1 && map[i][j+1]=='#') flg=1;
            }
            if(!flg){
                printf("No\n");
                return 0;
            }
        }
    }
    
    printf("Yes\n");

    return 0;
}

Submission status: Runtime Error

Solution code:
hw = [int(i) for i in input().split()]
h = hw[0]
w = hw[1]
rows = []
possible = True
for i in range(h):
  rows.append(input())
i = 0
if h==1 and w==1:
  if rows[0]=='#':
    possible = False
elif h==1 and w>1:
  i = 0
  while i<w:
    if rows[0][i]=='#':
      if i==0:
        if rows[0][i+1]=='.':
          possible = False
          break
      elif i==w-1:
        if rows[0][i-1]=='.':
          possible = False
          break
      else:
        if rows[0][i+1]=='.' and rows[0][i-1]=='.':
          possible = False
          break
    i+=1
elif h>1 and w==1:
  i = 0
  while i<h:
    if rows[i][0]=='#':
      if i==0:
        if rows[i+1][0]=='.':
          possible = False
          break
      elif i==h-1:
        if rows[i-1][0]=='.':
          possible = False
          break
      else:
        if rows[i+1][0]=='.' and rows[i-1][0]=='.':
          possible = False
          break
    i+=1
else:
  while i<h:
    j = 0
    while j<w:
      if rows[i][j]=='#':
        if i==0 and j==0:
          if rows[i][j+1]=='.' and rows[i+1][j]=='.':
            possible=False
            break
        elif i==0 and j>0:
          if rows[i][j+1]=='.' and rows[i][j-1]=='.' and rows[i+1][j]=='.':
            possible=False
            break
        elif i>0 and j==0:
          if rows[i+1][j]=='.' and rows[i-1][j]=='.' and rows[i][j+1]=='.':
            possible = False
            break
        elif i>0 and j==w-1:
          if rows[i+1][j]=='.' and rows[i-1][j]=='.' and rows[i][j-1]=='.':
            possible = False
            break
        elif i==h-1 and j>0:
          if rows[i][j+1]=='.' and rows[i-1][j]=='.' and rows[i][j-1]=='.':
            possible = False
            break
        elif i==h-1 and j==0:
          if rows[i-1][j]=='.' and rows[i][j+1]=='.':
            possible = False
            break
        elif i==0 and j==w-1:
          if rows[i+1][j]=='.' and rows[i][j-1]=='.':
            possible = False
            break
        elif i==h-1 and j==w-1:
          if rows[i-1][j]=='.' and rows[i][j-1]=='.':
            possible = False
            break
        else:
          if rows[i+1][j]=='.' and rows[i-1][j]=='.' and rows[i][j+1]=='.' and rows[i][j-1]=='.':
            possible = False
            break
      j+=1
    if possible==False:
      break
    i+=1
if possible==False:
  print("No")
else:
  print("Yes")

Submission status: Runtime Error

Solution code:
hw = [int(i) for i in input().split()]
h = hw[0]
w = hw[1]
rows = []
possible = True
for i in range(h):
  rows.append(input())
i = 0
if h==1 and w==1:
  if rows[0]=='#':
    possible = False
elif h==1 and w>1:
  i = 0
  while i<w:
    if rows[0][i]=='#':
      if i==0:
        if rows[0][i+1]=='.':
          possible = False
          break
      elif i==w-1:
        if rows[0][i-1]=='.':
          possible = False
          break
      else:
        if rows[0][i+1]=='.' and rows[0][i-1]=='.':
          possible = False
          break
    i+=1
elif h>1 and w==1:
  i = 0
  while i<h:
    if rows[i][0]=='#':
      if i==0:
        if rows[i+1][0]=='.':
          possible = False
          break
      elif i==h-1:
        if rows[i-1][0]=='.':
          possible = False
          break
      else:
        if rows[i+1][0]=='.' and rows[i-1][0]=='.':
          possible = False
          break
    i+=1
else:
  while i<h:
    j = i
    while j<w:
      if rows[i][j]=='#':
        if i==0 and j==0:
          if rows[i][j+1]=='.' and rows[i+1][j]=='.':
            possible=False
            break
        elif i==0 and j>0:
          if rows[i][j+1]=='.' and rows[i][j-1]=='.' and rows[i+1][j]=='.':
            possible=False
            break
        elif i>0 and j==0:
          if rows[i+1][j]=='.' and rows[i-1][j]=='.' and rows[i][j+1]=='.':
            possible = False
            break
        elif i>0 and j==w-1:
          if rows[i+1][j]=='.' and rows[i-1][j]=='.' and rows[i][j-1]=='.':
            possible = False
            break
        elif i==h-1 and j>0:
          if rows[i][j+1]=='.' and rows[i-1][j]=='.' and rows[i][j-1]=='.':
            possible = False
            break
        elif i==h-1 and j==0:
          if rows[i-1][j]=='.' and rows[i][j+1]=='.':
            possible = False
            break
        elif i==0 and j==w-1:
          if rows[i+1][j]=='.' and rows[i][j-1]=='.':
            possible = False
            break
        elif i==h-1 and j==w-1:
          if rows[i-1][j]=='.' and rows[i][j-1]=='.':
            possible = False
            break
        else:
          if rows[i+1][j]=='.' and rows[i-1][j]=='.' and rows[i][j+1]=='.' and rows[i][j-1]=='.':
            possible = False
            break
      j+=1
    if possible==False:
      break
    i+=1
if possible==False:
  print("No")
else:
  print("Yes")

Submission status: Runtime Error

Solution code:
H,W=map(int,input().split())
S=["."+input()+"." for i in range(H)]
S=["."*(W+2)]+S+["."*(W+2)]

flag=0

for k in range(1,H+1):
    for j in range(1,W+1):
        if field[k][j]=='#' and field[k-1][j]!='#' and field[k+1][j]!='#' and field[k][j-1]!='#' and field[k][j+1]!='#':
            flag=1

if flag==1:
    print('No')
else:     
    print('Yes')

Submission status: Runtime Error

Solution code:

H,W=map(int, input().split())
field=[[0]*(W+2) for i in range(H+2)]
List=[list(input()) for i in range(H)]

for k in range(1,H+1):
    for j in range(1,W+1):
        field[k][j] = List[k-1][j-1]

flag=1

for k in range(1,W+1):
    for j in range(1,H+1):
        if field[k][j]=='#' and field[k-1][j]!='#' and field[k+1][j]!='#' and field[k][j-1]!='#' and field[k][j+1]!='#':
            flag=0

if flag==1:     
    print('Yes')
else:
    print('No')

Submission status: Runtime Error

Solution code:

H,W=map(int, input().split())
field=[[0]*(W+1) for i in range(H+1)]
List=[list(input()) for i in range(H)]

for k in range(1,H):
    for j in range(1,W):
        field[k][j] = List[k-1][j-1]

#print(field)

flag=1

for k in range(1,W):
    for j in range(1,H):
        if field[k][j]=='#' and field[k-1][j]!='#' and field[k+1][j]!='#' and field[k][j-1]!='#' and field[k][j+1]!='#':
            flag=0

if flag==1:     
    print('Yes')
else:
    print('No')

Submission status: Runtime Error

Solution code:
H,W=map(int, input().split())
field=[[0]*(W+1) for i in range(H+1)]
List=[list(input()) for i in range(H)]

for k in range(1,H):
    for j in range(1,W):
        field[k][j] = List[k-1][j-1]

#print(field)

flag=1

for k in range(1,W):
    for j in range(1,H):
        if field[k][j]=='#' and field[k-1][j]!='#' and field[k+1][j]!='#' and field[k][j-1]!='#' and field[k][j+1]!='#':
            flag=0
            exit()

if flag==1:     
    print('Yes')
else:
    print('No')

Submission status: Runtime Error

Solution code:
H,W=map(int, input().split())
field=[[0]*(W+1) for i in range(H+1)]
List=[list(input()) for i in range(H)]

for k in range(1,H):
    for j in range(1,W):
        field[k][j] = List[k-1][j-1]

#print(field)

flag=1

for i in range(1,W):
    for j in range(1,H):
        if field[k][j]=='#' and field[k-1][j]!='#' and field[k+1][j]!='#' and field[k][j-1]!='#' and field[k][j+1]!='#':
            flag=0
            exit()

if flag==1:     
    print('Yes')
else:
    print('No')

Submission status: Runtime Error

Solution code:
H,W=map(int, input().split())
field=[[0]*(W+1) for i in range(H+1)]
List=[list(input()) for i in range(H)]

for k in range(1,H):
    for j in range(1,W):
        field[k][j] = List[k-1][j-1]

#print(field)

flag=1

for i in range(1,W):
    for j in range(1,H):
        if field[k][j]=='#' and field[k-1][j]!='#' and field[k+1][j]!='#' and field[k][j-1]!='#' and field[k][j+1]!='#':
            print('No')
            flag=0
            exit()

if flag==1:     
    print('Yes')

Submission status: Runtime Error

Solution code:
H,W=map(int, input().split())
field=[[0]*(W+1) for i in range(H+1)]
List=[list(input()) for i in range(H)]

for k in range(1,H):
    for j in range(1,W):
        field[k][j] = List[k-1][j-1]

#print(field)

flag=1

for i in range(W+1):
    for j in range(H+1):
        if field[k][j]=='#' and field[k-1][j]!='#' and field[k+1][j]!='#' and field[k][j-1]!='#' and field[k][j+1]!='#':
            print('No')
            flag=0
            exit()

if flag==1:     
    print('Yes')

Submission status: Runtime Error

Solution code:
h, w = map(int, input().split())
grid = [list(input()) for _ in range(h)]

check = [(-1, 0), (0, -1), (1, 0), (0, 1)]
for j in range(h):
  for i in range(w):
    if grid[i][j] == "#":
      temp = [(i+cx, j+cy) for cx, cy in check if (0<= i+cx <w and 0<= j+cy <h)]
      count = 0
      for t_cx, t_cy in temp:
        if grid[t_cx][t_cy] == "#":
          count += 1
      if count == 0:
        print("No")
        exit()
print("Yes")

Submission status: Runtime Error

Solution code:
h,w=map(int,input().split())
dx=[-1,1,0,0]
dy=[0,0,-1,1]
a=[]
for i in range(h):
    a.append(list(input()))
for i in range(h):
    for j in range(w):
        frag=False
        if a[i][j]=="#":
            for k in range(4):
                x=j+dx[k]
                y=i+dy[k]
                if x<0 or x>w-1 or y<0 or y>h-1:
                    continue
                if a[x][y]=="#":
                    frag=True
            if frag==False:
                print("No")
                exit()
print("Yes")

Submission status: Runtime Error

Solution code:
import sys
h,w=map(int,input().split())
lst=[[0 for i in range(w)]for j in range(h)]
for i in range(h):
  s=input().split()
  for j in range(len(s)):
    if s[j]=='#':
      lst[i][j]=1
if h,w==1,1:
  print('Yes')
  sys.exit()
for j in range(1,h-1):
  for k in range(1,w-1):
    if lst[j][k]==1:
      if lst[j-1][k]!=1 and lst[j+1][k]!=1 and lst[j][k-1]!=1 and lst[j][k+1]!=1:
        print('No')
        sys.exit()
if lst[0][0]==1:
  if lst[0][1]!=1 and lst[1][0]!=1:
    print('No')
    sys.exit()
if lst[h-1][0]==1:
  if lst[h-2][0]!=1 and lst[h-1][1]!=1:
    print('No')
    sys.exit()
if lst[0][k-1]==1:
  if lst[0][k-2]!=1 and lst[1][k-1]!=1:
    print('No')
    sys.exit()
if lst[h-1][k-1]==1:
  if lst[h-1][k-2]!=1 and lst[h-2][k-1]!=1:
    print('No')
    sys.exit()

print('Yes')

Submission status: Runtime Error

Solution code:
import sys
h,w=map(int,input().split())
lst=[[0 for i in range(w)]for j in range(h)]
for i in range(h):
  s=input().split()
  for j in len(s):
    if s[j]=='#':
      lst[i][j]=1

for j in range(h-2):
  for k in range(w-2):
    if lst[j][k]*lst[j][k+1]==0 and lst[j][k+1]*lst[j][k+2]==0:
      print('No')
      sys.exit()
    if lst[j][k]*lst[j+1][k]==0 and lst[j+1][k]*lst[j+2][k]==0:
      print('No')
      sys.exit()
    
print('Yes')