Problem p03361 (python)

Fixed submission:
#!/usr/bin/env python3
import sys
import numpy as np

YES = "Yes"  # type: str
NO = "No"  # type: str


def solve(H: int, W: int, s: "List[str]"):
    ans = YES
    for i in range(1, H-1):
        for j in range(1, W-1):
            if s[i][j] == "#" and s[i-1][j] == s[i+1][j] == s[i][j-1] == s[i][j+1] == ".":
                ans = NO
    print(ans)

# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    H, W = map(int,input().split())  # type: int
    s = [input() for _ in range(H)]  # type: "List[str]"
    solve(H, W, s)

if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
#!/usr/bin/env python3
import sys
import numpy as np

YES = "Yes"  # type: str
NO = "No"  # type: str


def solve(H: int, W: int, s: "List[str]"):
    ans = YES
    for i in range(1, H-1):
        for j in range(1, W-1):
            if s[i][j] == "#" and s[i-1][j] == s[i+1][j] == s[i][j-1] == s[i][j+1] == ".":
                ans = NO
    print(ans)

# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    H = int(next(tokens))  # type: int
    W = int(next(tokens))  # type: int
    s = [next(tokens) for _ in range(W)]  # type: "List[str]"
    solve(H, W, s)

if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
#!/usr/bin/env python3
import sys
import numpy as np

YES = "Yes"  # type: str
NO = "No"  # type: str


def solve(H: int, W: int, s: "List[str]"):
    def chk_neighbor(i, j):
        if i < 0 or j < 0 or i >= H or j >= W:
            return "."
        else:
            return s[i][j]

    count = 0
    numofshirp = 0
    for s_ in s:
        numofshirp += s_.count("#")

    for i in range(H):
        for j in range(W):
            if s[i][j] == "#":
                if "#" in [chk_neighbor(i - 1, j), chk_neighbor(i + 1, j), chk_neighbor(i, j - 1), chk_neighbor(i, j + 1)]:
                    count += 1

    if count == numofshirp:
        print(YES)
    else:
        print(NO)

# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    H = int(next(tokens))  # type: int
    W = int(next(tokens))  # type: int
    s = [next(tokens) for _ in range(W)]  # type: "List[str]"
    solve(H, W, s)

if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
#!/usr/bin/env python3
import sys
import numpy as np

YES = "Yes"  # type: str
NO = "No"  # type: str

def solve(H: int, W: int, s: "List[str]"):
    count = 0
    numofshirp = 0
    for s_ in s:
        numofshirp += s_.count("#")

    #padding
    edge = ["".join(["."] * (W + 2))]
    for i, si in enumerate(s):
        s[i] = "".join("."+si+".")
    s.extend(edge)
    edge.extend(s)

    for i, ei in enumerate(edge):
        for j, eij in enumerate(ei):
            if eij == "#" and i > 0 and j > 0 and i < len(edge) - 1 and j < len(edge[0]) - 1:
                if "#" in (edge[i - 1][j], edge[i + 1][j], edge[i][j - 1], edge[i][j + 1]):
                    count += 1

    if count == numofshirp:
        print(YES)
    else:
        print(NO)

# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    H = int(next(tokens))  # type: int
    W = int(next(tokens))  # type: int
    s = [next(tokens) for _ in range(W)]  # type: "List[str]"
    solve(H, W, s)

if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
#!/usr/bin/env python3
import sys
import numpy as np

YES = "Yes"  # type: str
NO = "No"  # type: str

def solve(H: int, W: int, s: "List[str]"):
    count = 0
    numofshirp = 0
    for s_ in s:
        numofshirp += s_.count("#")

    #padding
    edge = ["".join(["."] * (W + 2))]
    for i, si in enumerate(s):
        s[i] = "".join("."+si+".")
    s.extend(edge)
    edge.extend(s)

    for i, ei in enumerate(edge):
        for j, eij in enumerate(ei):
            if eij == "#" and i > 0 and j > 0:
                if "#" in (edge[i - 1][j], edge[i + 1][j], edge[i][j - 1], edge[i][j + 1]):
                    count += 1

    if count == numofshirp:
        print(YES)
    else:
        print(NO)

# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    H = int(next(tokens))  # type: int
    W = int(next(tokens))  # type: int
    s = [next(tokens) for _ in range(W)]  # type: "List[str]"
    solve(H, W, s)

if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
#!/usr/bin/env python3
import sys
import numpy as np

YES = "Yes"  # type: str
NO = "No"  # type: str

def solve(H: int, W: int, s: "List[str]"):
    count = 0
    numofshirp = 0
    for s_ in s:
        numofshirp += s_.count("#")

    #padding
    edge = ["".join(["."] * (W + 2))]
    for i, si in enumerate(s):
        s[i] = "".join("."+si+".")
    s.extend(edge)
    edge.extend(s)

    for i, ei in enumerate(edge):
        for j, eij in enumerate(ei):
            if eij == "#":
                if "#" in (edge[i - 1][j], edge[i + 1][j], edge[i][j - 1], edge[i][j + 1]):
                    count += 1

    if count == numofshirp:
        print(YES)
    else:
        print(NO)

# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    H = int(next(tokens))  # type: int
    W = int(next(tokens))  # type: int
    s = [next(tokens) for _ in range(W)]  # type: "List[str]"
    solve(H, W, s)

if __name__ == '__main__':
    main()