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
from itertools import accumulate

import numpy as np

h, w = list(map(int, input().split()))
field = [[int(c == '.') for c in line.rstrip()] for line in sys.stdin]
func = lambda x, a: (x + a) * a
ans = np.zeros([h, w], dtype=np.int)

for i, row in enumerate(field):
    ans[i] += list(accumulate(row, func=func))
    ans[i] += list(reversed(list(accumulate(reversed(row), func=func))))

ans = ans.T
field = np.array(field).T.tolist()
for i, row in enumerate(field):
    ans[i] += list(accumulate(row, func=func))
    ans[i] += list(reversed(list(accumulate(reversed(row), func=func))))

print(ans.max() - 3)


import sys
import numpy as np

h, w = list(map(int, input().split()))
field = np.array([[1 if '.' else 0 for c in line.rstrip()] for line in sys.stdin])

lr = np.zeros((h, w), dtype=np.int)
ud = np.zeros((w, h), dtype=np.int)

for row, lrr in zip(field, lr):
    tmp = 0
    for j, c in enumerate(row):
        tmp = tmp + 1 if c == 1 else 0
        lrr[j] += tmp
    tmp = 0
    for j, c in enumerate(list(enumerate(row))):
        tmp = tmp + 1 if c == 1 else 0
        lrr[j] += tmp
for row, lrr in zip(field.T, ud):
    tmp = 0
    for j, c in enumerate(row):
        tmp = tmp + 1 if c == 1 else 0
        lrr[j] += tmp
    tmp = 0
    for j, c in enumerate(list(enumerate(row))):
        tmp = tmp + 1 if c == 1 else 0
        lrr[j] += tmp

print((lr + ud.T).max() - 3)


import sys

import numpy as np

h, w = list(map(int, input().split()))
field = [[int(c == '.') for c in line.rstrip()] for line in sys.stdin]
field = np.array(field)


def cumsum(f):
    result = np.zeros((h, w), dtype=np.int)
    for i, row in enumerate(f):
        ri = result[i]
        tmp = 0
        for j, c in enumerate(row):
            tmp = (tmp + c) * c
            ri[j] += tmp
        tmp = 0
        for j, c in reversed(list(enumerate(row))):
            tmp = (tmp + c) * c
            ri[j] += tmp
    return result


ans = cumsum(field)
ans += cumsum(field.T).T

print(ans.max() - 3)


import sys
import numpy as np

h, w = list(map(int, input().split()))
field = np.array([[c == '.' for c in line.rstrip()] for line in sys.stdin], dtype=np.int32)
li, ri, ui, di = (field.copy() for _ in [0] * 4)

for i in range(1, h):
    ui[i] = (ui[i - 1] + 1) * field[i]
    di[h - i - 1] = (di[h - i] + 1) * field[h - i - 1]
field = field.T
li, ri = li.T, ri.T
for j in range(1, w):
    li[j] = (li[j - 1] + 1) * field[j]
    ri[w - j - 1] = (ri[w - j] + 1) * field[w - j - 1]
li, ri = li.T, ri.T
print((li + ri + ui + di).max() - 3)


Verdicts: Time Limit Exceeded

Wrong Answer

Runtime Error

Accepted