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):
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import numpy


def main():
  r, c = map(int, input().split())
  g = [input().strip() for _ in range(r)]
  v = numpy.zeros((2, r, c), dtype=numpy.int)

  for y in range(r):
    s = 0
    for x in range(c):
      if g[y][x] == '#':
        v[0, y, s:x] = x - s
        s = x + 1

    v[0, y, s:] = c - s

  for x in range(c):
    s = 0
    for y in range(r):
      if g[y][x] == '#':
        v[1, s:y, x] = y - s
        s = x + 1

    v[1, s:, x] = r - s

  v = v[0] + v[1]

  print(numpy.max(v) - 1)


if __name__ == '__main__':
  main()



#!/usr/bin/env python
# -*- coding: utf-8 -*-
import numpy


def main():
  r, c = map(int, input().split())
  g = numpy.array([[1 if v == '.' else 0 for v in input().strip()] for _ in range(r)])
  g = numpy.stack([g, g])

  print(g[0])

  for x in range(1, c):
    g[0, :, x] += g[0, :, x] * g[0, :, x - 1]

  for x in range(c - 2, -1, -1):
    g[0, :, x] = (g[0, :, x] != 0) * numpy.maximum(g[0, :, x], g[0, :, x + 1])

  for y in range(1, r):
    g[1, y] += g[1, y] * g[1, y - 1]

  for y in range(r - 2, -1, -1):
    g[1, y] = (g[1, y] != 0) * numpy.maximum(g[1, y], g[1, y + 1])

  g = g[0] + g[1]

  print(numpy.max(g) - 1)


if __name__ == '__main__':
  main()



#!/usr/bin/env python
# -*- coding: utf-8 -*-
import numpy


def main():
  r, c = map(int, input().split())
  g = [[1 if v == '.' else 0 for v in input().strip()] for _ in range(r)]
  v = numpy.zeros((r, c), dtype=numpy.int)

  for y in range(r):
    s = 0
    for x in range(c):
      if g[y][x] == 0:
        v[y, s:x] += x - s
        s = x + 1

    v[y, s:] += c - s

  for x in range(c):
    s = 0
    for y in range(r):
      if g[y][x] == 0:
        v[s:y, x] += y - s
        s = y + 1

    v[s:, x] += r - s

  print(numpy.max(v) - 1)


if __name__ == '__main__':
  main()



#!/usr/bin/env python
# -*- coding: utf-8 -*-
import numpy


def main():
  r, c = map(int, input().split())
  g = [[1 if v == '.' else 0 for v in input().strip()] for _ in range(r)]
  v = numpy.zeros((2, r, c), dtype=numpy.int)

  for y in range(r):
    s = 0
    for x in range(c):
      if g[y][x] == 0:
        v[0, y, s:x] = x - s
        s = x + 1

    v[0, y, s:] = c - s

  for x in range(c):
    s = 0
    for y in range(r):
      if g[y][x] == 0:
        v[1, s:y, x] = y - s
        s = y + 1

    v[1, s:, x] = r - s

  v = v[0] + v[1]

  print(numpy.max(v) - 1)


if __name__ == '__main__':
  main()



#!/usr/bin/env python
# -*- coding: utf-8 -*-
import numpy


def main():
  r, c = map(int, input().split())
  g = numpy.array([[1 if v == '.' else 0 for v in input().strip()] for _ in range(r)])
  g = numpy.array([g, g])

  for x in range(1, c):
    g[0, :, x] += g[0, :, x] * g[0, :, x - 1]

  for x in range(c - 2, -1, -1):
    g[0, :, x] = (g[0, :, x] != 0) * numpy.maximum(g[0, :, x], g[0, :, x + 1])

  for y in range(1, r):
    g[1, y] += g[1, y] * g[1, y - 1]

  for y in range(r - 2, -1, -1):
    g[1, y] = (g[1, y] != 0) * numpy.maximum(g[1, y], g[1, y + 1])

  g = g[0] + g[1]

  print(numpy.max(g) - 1)


if __name__ == '__main__':
  main()



Verdicts: Wrong Answer

Runtime Error

Time Limit Exceeded

Time Limit Exceeded

Accepted