Problem: There is a grid with H horizontal rows and W vertical columns, and there are obstacles on some of the squares.  Snuke is going to choose one of the squares not occupied by an obstacle and place a lamp on it. The lamp placed on the square will emit straight beams of light in four cardinal directions: up, down, left, and right. In each direction, the beam will continue traveling until it hits a square occupied by an obstacle or it hits the border of the grid. It will light all the squares on the way, including the square on which the lamp is placed, but not the square occupied by an obstacle.  Snuke wants to maximize the number of squares lighted by the lamp.  You are given H strings S_i (1 \leq i \leq H), each of length W. If the j-th character (1 \leq j \leq W) of S_i is `#`, there is an obstacle on the square at the i-th row from the top and the j-th column from the left; if that character is `.`, there is no obstacle on that square.  Find the maximum possible number of squares lighted by the lamp.

Submission attempts (in order):
import sys
import numpy as np


def read():
    return sys.stdin.readline().rstrip()


def main():
    h, w = map(int, read().split())
    s = np.array([[i == "." for i in read()] for _ in range(h)], dtype=int)
    left = s.copy()
    right = s.copy
    up = s.copy
    down = s.copy
    for i in range(w - 1):
        left[:, i + 1] = (left[:, i] + 1) * s[:, i + 1]
        right[:, -i - 2] = (right[:, -i - 1] + 1) * s[:, -i - 2]
    for i in range(h - 1):
        up[i + 1] = (up[i] + 1) * s[i + 1]
        down[-i - 2] = (down[-i - 1] + 1) * s[-i - 2]
    print((left + right + up + down).max() - 3)


if __name__ == '__main__':
    main()


import sys

def read():
    return sys.stdin.readline().rstrip()

def main():
    h, w = map(int, read().split())
    s = [list(read()) for _ in range(h)]
    row = [[0 for _ in range(w)] for _ in range(h)]
    col = [[0 for _ in range(w)] for _ in range(h)]
    for i in range(h):
        c = 0
        for j in range(w):
            if s[i][j] == "#":
                for k in range(j - c, j):
                    row[i][k] = c
                c = 0
            else:
                c += 1
        for k in range(w - c, w):
            row[i][k] = c
    for i in range(w):
        c = 0
        for j in range(h):
            if s[j][i] == "#":
                for k in range(j - c, j):
                    col[k][i] = c
                c = 0
            else:
                c += 1
        for k in range(h - c, h):
            col[k][i] = c
    ans = 0
    for i in range(h):
        for j in range(w):
            ans = max(row[i][j] + col[i][j], ans)
    print(ans)

if __name__ == '__main__':
    main()

import numpy as np


def main():
    h, w = map(int, input().split())
    s = np.array([[i == "." for i in input()] for _ in range(h)], dtype=int)
    left = s.copy()
    right = s.copy()
    up = s.copy()
    down = s.copy()
    for i in range(w - 1):
        left[:, i + 1] = (left[:, i] + 1) * s[:, i + 1]
        right[:, -i - 2] = (right[:, -i - 1] + 1) * s[:, -i - 2]
    for i in range(h - 1):
        up[i + 1] = (up[i] + 1) * s[i + 1]
        down[-i - 2] = (down[-i - 1] + 1) * s[-i - 2]
    print((left + right + up + down).max() - 3)


if __name__ == '__main__':
    main()


Verdicts: Runtime Error

Wrong Answer

Accepted