Problem:


Score : 400 points

Problem Statement

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.

Constraints

1 \leq H \leq 2,000

1 \leq W \leq 2,000

S_i is a string of length W consisting of # and ..

. occurs at least once in one of the strings S_i (1 \leq i \leq H).

Input

Input is given from Standard Input in the following format:

H W
S_1
:
S_H

Output

Print the maximum possible number of squares lighted by the lamp.

Sample Input 1

4 6
#..#..
.....#
....#.
#.#...

Sample Output 1

8

If Snuke places the lamp on the square at the second row from the top and the second column from the left, it will light the following squares: the first through fifth squares from the left in the second row, and the first through fourth squares from the top in the second column, for a total of eight squares.

Sample Input 2

8 8
..#...#.
....#...
##......
..###..#
...#..#.
##....#.
#...#...
###.#..#

Sample Output 2

13



Sample input:
4 6
#..#..
.....#
....#.
#.#...


Sample output:
8

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin/env python3

import numpy as np


def solve(H, W, S):
    grid = np.zeros(H*W, dtype=np.int)
    for y in range(H):
        count = 0
        start = 0
        yw = y * W
        for x in range(W):
            if S[y][x] == '#':
                grid[yw+start:yw+x] = count
                start = x + 1
                count = 0
            else:
                count += 1
        grid[yw+start:yw+W] = count

    for x in range(W):
        count = 0
        start = 0
        for y in range(H):
            if S[y][x] == '#':
                grid[(start*W+x):(y*W+x):W] += count
                start = y + 1
                count = 0
            else:
                count += 1

        grid[(start*W+x):(H*W+1):W] += count

    return grid.max() - 1


if __name__ == '__main__':
    H, W = map(int, input().split())
    S = [input().strip() for _ in range(H)]

    ans = solve(H, W, S)

    print(ans)

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin/env python3

import numpy as np


def solve(H, W, S):
    grid = np.zeros(H*W, dtype=np.int)
    for y in range(H):
        count = 0
        start = 0
        yw = y * W
        for x in range(W):
            if S[y][x] == '#':
                grid[yw+start:yw+x] = count
                start = x + 1
                count = 0
            else:
                count += 1
        grid[yw+start:yw+W] = count

    ans = 1
    for x in range(W):
        count = 0
        start = 0
        for y in range(H):
            if S[y][x] == '#':
                for i in range(start, y):
                    if ans < grid[i*W+x] + count:
                        ans = grid[i*W+x] + count
                start = y + 1
                count = 0
            else:
                count += 1
        for i in range(start, H):
            if ans < grid[i*W+x] + count:
                ans = grid[i*W+x] + count

    return ans - 1


if __name__ == '__main__':
    H, W = map(int, input().split())
    S = [input().strip() for _ in range(H)]

    ans = solve(H, W, S)

    print(ans)

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin/env python3


def solve(H, W, S):
    grid = [0] * (W * H)
    for y in range(H):
        count = 0
        start = 0
        yw = y * W
        for x in range(W):
            if S[y][x] == '#':
                for i in range(start, x):
                    grid[yw+i] = count
                start = x + 1
                count = 0
            else:
                count += 1
        for i in range(start, W):
            grid[yw+i] = count

    ans = 1
    for x in range(W):
        count = 0
        start = 0
        for y in range(H):
            if S[y][x] == '#':
                for i in range(start, y):
                    if ans < grid[i*W+x] + count:
                        ans = grid[i*W+x] + count
                start = y + 1
                count = 0
            else:
                count += 1
        for i in range(start, H):
            if ans < grid[i*W+x] + count:
                ans = grid[i*W+x] + count

    return ans - 1


if __name__ == '__main__':
    H, W = map(int, input().split())
    S = [input().strip() for _ in range(H)]

    ans = solve(H, W, S)

    print(ans)

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin/env python3


def solve(H, W, S):
    grid = [0] * (W * H)
    for y in range(H):
        count = 0
        start = 0
        for x in range(W):
            if S[y][x] == '#':
                for i in range(start, x):
                    grid[y*W+i] = count
                start = x + 1
                count = 0
            else:
                count += 1
        for i in range(start, W):
            grid[y*W+i] = count

    ans = 1
    for x in range(W):
        count = 0
        start = 0
        for y in range(H):
            if S[y][x] == '#':
                for i in range(start, y):
                    if ans < grid[i*W+x] + count:
                        ans = grid[i*W+x] + count
                start = y + 1
                count = 0
            else:
                count += 1
        for i in range(start, H):
            if ans < grid[i*W+x] + count:
                ans = grid[i*W+x] + count

    return ans - 1


if __name__ == '__main__':
    H, W = map(int, input().split())
    S = [input().strip() for _ in range(H)]

    ans = solve(H, W, S)

    print(ans)

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin/env python3


def solve(H, W, S):
    grid = [[0] * W for _ in range(H)]
    for y in range(H):
        count = 0
        start = 0
        for x in range(W):
            if S[y][x] == '#':
                for i in range(start, x):
                    grid[y][i] = count
                start = x + 1
                count = 0
            else:
                count += 1
        for i in range(start, W):
            grid[y][i] = count

    ans = 1
    for x in range(W):
        count = 0
        start = 0
        for y in range(H):
            if S[y][x] == '#':
                for i in range(start, y):
                    if ans < grid[i][x] + count:
                        ans = grid[i][x] + count
                start = y + 1
                count = 0
            else:
                count += 1
        for i in range(start, H):
            if ans < grid[i][x] + count:
                ans = grid[i][x] + count

    return ans - 1


if __name__ == '__main__':
    H, W = map(int, input().split())
    S = [input().strip() for _ in range(H)]

    ans = solve(H, W, S)

    print(ans)

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin/env python3


def solve(H, W, S):
    grid = [[0] * W for _ in range(H)]
    for y in range(H):
        count = 0
        start = 0
        for x in range(W):
            if S[y][x] == '#':
                for i in range(start, x):
                    grid[y][i] = count
                start = x + 1
                count = 0
            else:
                count += 1
        for i in range(start, W):
            grid[y][i] = count

    for x in range(W):
        count = 0
        start = 0
        for y in range(H):
            if S[y][x] == '#':
                for i in range(start, y):
                    grid[i][x] += count
                start = y + 1
                count = 0
            else:
                count += 1
        for i in range(start, H):
            grid[i][x] += count

    ans = 0
    for x in range(W):
        for y in range(H):
            if grid[y][x] > ans:
                ans = grid[y][x]
    return ans - 1


if __name__ == '__main__':
    H, W = map(int, input().split())
    S = [input().strip() for _ in range(H)]

    ans = solve(H, W, S)

    print(ans)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

H, W = list(map(int, input().split()))
S = np.array([list(input()) for _ in range(H)])

ans = np.zeros((H, W))
for s, x in zip(S, ans):
    v = 0
    for j in range(W - 1):
        if s[j] == "#":
            x[v:j] = j - v
            x[j] = np.nan
            v = j + 1
    if s[-1] == "#":
        x[v:-1] = W - 1 - v
        x[-1] = np.nan
    else:
        x[v:] = W - v
            
for s, y in zip(S.T, ans.T):
    v = 0
    for j in range(H - 1):
        if s[j] == "#":
            y[v:j] += j - v
            y[j] = np.nan
            v = j + 1
    if s[-1] == "#":
        y[v:-1] += H - 1 - v
        y[-1] = np.nan
    else:
        y[v:] += H - v
        
print(int(np.nanmax(ans)) - 1)

Submission status: Time Limit Exceeded

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

ans = []
dp = [[(None, None)] * (W + 1) for _ in range(H + 1)]
for i in range(H):
    s = S[i]
    for j in range(W):
        if s[j] == "#":
            dp[i+1][j+1] = (None, None)
            continue
        x, y = dp[i+1][j][0], dp[i][j+1][1]
        if x is None:
            count = 1
            for s_ in s[j+1:]:
                if s_ == "#":
                    break
                count += 1
            x = count
        if y is None:
            count = 1
            for i_ in range(i+1, H):
                if S[i_][j] == "#":
                    break
                count += 1
            y = count
        ans.append(x + y - 1)
        dp[i+1][j+1] = (x, y)
print(max(ans))

Submission status: Time Limit Exceeded

Solution code:
h, w = map(int, input().split())
s = [input() + '#' for _ in range(h)]
s.append('#' * (w + 1))
t = [[-1] * w for _ in range(h + 1)]
tstart = [-1] * (w + 1)
for i in range(h + 1):
  ystart = -1
  for j in range(w + 1):
    if s[i][j] == '#':
      if ystart != -1:
        for k in range(ystart, j):
          t[i][k] += j - ystart
        ystart = -1
      if tstart[j] != -1:
        for k in range(tstart[j], i):
          t[k][j] += i - tstart[j]
        tstart[j] = -1
    else:
      if ystart == -1:
        ystart = j
      if tstart[j] == -1:
        tstart[j] = i
print(max(map(max, t)))

Submission status: Time Limit Exceeded

Solution code:
def main():
  _max = max
  _range = range
  _input = input
  h, w = map(int, _input().split())
  s = [_input() + '#' for _ in _range(h)]
  s.append('#' * (w + 1))

  rt = [[-1] * w for _ in _range(h + 1)]
  tstart = [-1] * (w + 1)
  i = 0
  while i < h + 1:
    si = s[i]
    rti = rt[i]
    ystart = -1
    j = 0
    while j < w + 1:
      tj = tstart[j]
      if si[j] == '#':
        if ystart != -1:
          jy = j - ystart
          for k in _range(ystart, j):
            rti[k] += jy
          ystart = -1
        if tj != -1:
          itj = i - tj
          for k in _range(tj, i):
            rt[k][j] += itj
          tstart[j] = -1
      else:
        if ystart == -1:
          ystart = j
        if tj == -1:
          tstart[j] = i
      j += 1
    i += 1

  print(_max(map(_max, rt)))

main()

Submission status: Time Limit Exceeded

Solution code:
def main():
  _max = max
  _range = range
  _input = input
  h, w = map(int, _input().split())
  s = [_input() + '#' for _ in _range(h)]
  s.append('#' * (w + 1))

  rt = [[-1] * w for _ in _range(h + 1)]
  tstart = [-1] * (w + 1)
  for i in _range(h + 1):
    si = s[i]
    rti = rt[i]
    ystart = -1
    for j in _range(w + 1):
      tj = tstart[j]
      if si[j] == '#':
        if ystart != -1:
          jy = j - ystart
          for k in _range(ystart, j):
            rti[k] += jy
          ystart = -1
        if tj != -1:
          itj = i - tj
          for k in _range(tj, i):
            rt[k][j] += itj
          tstart[j] = -1
      else:
        if ystart == -1:
          ystart = j
        if tj == -1:
          tstart[j] = i

  print(_max(map(_max, rt)))

main()

Submission status: Time Limit Exceeded

Solution code:
def main():
  _max = max
  _range = range
  _input = input
  h, w = map(int, _input().split())
  s = [_input() + '#' for _ in _range(h)]
  s.append('#' * (w + 1))

  rt = [[-1] * w for _ in _range(h + 1)]

  tstart = [-1] * (w + 1)
  for i in _range(h + 1):
    si = s[i]
    rti = rt[i]
    ystart = -1
    for j in _range(w + 1):
      tj = tstart[j]
      if si[j] == '#':
        if ystart != -1:
          jy = j - ystart
          for k in _range(ystart, j):
            rti[k] += jy
          ystart = -1
        if tj != -1:
          itj = i - tj
          for k in _range(tj, i):
            rt[k][j] += itj
          tstart[j] = -1
      else:
        if ystart == -1:
          ystart = j
        if tj == -1:
          tstart[j] = i

  print(_max(map(_max, rt)))

main()

Submission status: Time Limit Exceeded

Solution code:
def main():
  _max = max
  _range = range
  _input = input
  h, w = map(int, _input().split())
  s = [_input() + '#' for _ in _range(h)]
  s.append('#' * (w + 1))

  rt = [[-1] * w for _ in _range(h + 1)]

  tstart = [-1] * (w + 1)
  for i in _range(h + 1):
    si = s[i]
    rti = rt[i]
    ystart = -1
    for j in _range(w + 1):
      tj = tstart[j]
      if si[j] == '#':
        if ystart != -1:
          jy = j - ystart
          for k in _range(ystart, j):
            rti[k] += jy
          ystart = -1
        if tj != -1:
          itj = i - tj
          for k in _range(tj, i):
            rt[k][j] += itj
          tstart[j] = -1
      else:
        if ystart == -1:
          ystart = j
        if tj == -1:
          tstart[j] = i

  print(_max(_max(l) for l in rt))

main()

Submission status: Time Limit Exceeded

Solution code:
def main():
  _max = max
  _range = range
  h, w = map(int, input().split())
  s = [input() + '#' for _ in _range(h)]
  s.append('#' * (w + 1))

  rt = [[-1] * w for _ in _range(h + 1)]

  tstart = [-1] * (w + 1)
  for i in _range(h + 1):
    si = s[i]
    rti = rt[i]
    ystart = -1
    for j in _range(w + 1):
      tj = tstart[j]
      if si[j] == '#':
        if ystart != -1:
          jy = j - ystart
          for k in _range(ystart, j):
            rti[k] += jy
          ystart = -1
        if tj != -1:
          itj = i - tj
          for k in _range(tj, i):
            rt[k][j] += itj
          tstart[j] = -1
      else:
        if ystart == -1:
          ystart = j
        if tj == -1:
          tstart[j] = i

  print(_max(_max(l) for l in rt))

main()

Submission status: Time Limit Exceeded

Solution code:
def main():
  _max = max
  from itertools import chain
  h, w = map(int, input().split())
  s = [input() + '#' for _ in range(h)]
  s.append('#' * (w + 1))

  rt = [[-1] * (w + 1) for _ in range(h + 1)]

  tstart = [-1] * (w + 1)
  for i in range(h + 1):
    si = s[i]
    rti = rt[i]
    ystart = -1
    for j in range(w + 1):
      if si[j] == '#':
        if ystart != -1:
          jy = j - ystart
          for k in range(ystart, j):
            rti[k] += jy
          ystart = -1
        tj = tstart[j]
        if tj != -1:
          itj = i - tj
          for k in range(tj, i):
            rt[k][j] += itj
          tstart[j] = -1
      else:
        if ystart == -1:
          ystart = j
        if tstart[j] == -1:
          tstart[j] = i

  print(_max(chain.from_iterable(rt)))

main()

Submission status: Time Limit Exceeded

Solution code:
def main():
  _max = max
  h, w = map(int, input().split())
  s = [input() for _ in range(h)]

  rt = [[-1] * w for _ in range(h + 1)]

  tstart = [-1] * (w)
  for i in range(h):
    si = s[i]
    rti = rt[i]
    ystart = -1
    for j in range(w):
      tj = tstart[j]
      if si[j] == '#':
        if ystart != -1:
          jy = j - ystart
          for k in range(ystart, j):
            rti[k] += jy
          ystart = -1
        if tj != -1:
          itj = i - tj
          for k in range(tj, i):
            rt[k][j] += itj
          tstart[j] = -1
      else:
        if ystart == -1:
          ystart = j
        if tj == -1:
          tstart[j] = i

    if ystart != -1:
      jy = w - ystart
      for k in range(ystart, w):
        rti[k] += jy

  for j in range(w):
    tj = tstart[j]
    if tj != -1:
      itj = h - tj
      for k in range(tj, h):
        rt[k][j] += itj
      tstart[j] = -1

  print(_max(sum(rt, [])))

main()

Submission status: Time Limit Exceeded

Solution code:
def main():
  _max = max
  h, w = map(int, input().split())
  s = [input() for _ in range(h)]

  rt = [[-1] * w for _ in range(h + 1)]

  tstart = [-1] * (w)
  for i in range(h):
    si = s[i]
    rti = rt[i]
    ystart = -1
    for j in range(w):
      tj = tstart[j]
      if si[j] == '#':
        if ystart != -1:
          jy = j - ystart
          for k in range(ystart, j):
            rti[k] += jy
          ystart = -1
        if tj != -1:
          itj = i - tj
          for k in range(tj, i):
            rt[k][j] += itj
          tstart[j] = -1
      else:
        if ystart == -1:
          ystart = j
        if tj == -1:
          tstart[j] = i

    if ystart != -1:
      jy = w - ystart
      for k in range(ystart, w):
        rti[k] += jy

  for j in range(w):
    tj = tstart[j]
    if tj != -1:
      itj = h - tj
      for k in range(tj, h):
        rt[k][j] += itj
      tstart[j] = -1

  print(_max(_max(l) for l in rt))

main()

Submission status: Time Limit Exceeded

Solution code:
def main():
  h, w = map(int, input().split())
  s = [input() + '#' for _ in range(h)]
  s.append('#' * (w + 1))

  rt = [[-1] * w for _ in range(h + 1)]

  result = 0
  tstart = [-1] * (w + 1)
  for i in range(h + 1):
    si = s[i]
    rti = rt[i]
    ystart = -1
    for j in range(w + 1):
      tj = tstart[j]
      if si[j] == '#':
        if ystart != -1:
          jy = j - ystart
          for k in range(ystart, j):
            rti[k] += jy
            if rti[k] > result:
              result = rti[k]
          ystart = -1
        if tj != -1:
          itj = i - tj
          for k in range(tj, i):
            rt[k][j] += itj
            if rt[k][j] > result:
              result = rt[k][j]
          tstart[j] = -1
      else:
        if ystart == -1:
          ystart = j
        if tj == -1:
          tstart[j] = i

  print(result)

main()

Submission status: Time Limit Exceeded

Solution code:
def main():
  _max = max
  h, w = map(int, input().split())
  s = [input() + '#' for _ in range(h)]
  s.append('#' * (w + 1))

  rt = [[-1] * w for _ in range(h + 1)]

  tstart = [-1] * (w + 1)
  for i in range(h + 1):
    si = s[i]
    rti = rt[i]
    ystart = -1
    for j in range(w + 1):
      tj = tstart[j]
      if si[j] == '#':
        if ystart != -1:
          jy = j - ystart
          for k in range(ystart, j):
            rti[k] += jy
          ystart = -1
        if tj != -1:
          itj = i - tj
          for k in range(tj, i):
            rt[k][j] += itj
          tstart[j] = -1
      else:
        if ystart == -1:
          ystart = j
        if tj == -1:
          tstart[j] = i

  print(_max(_max(l) for l in rt))

main()

Submission status: Time Limit Exceeded

Solution code:
def main():
  _max = max
  h, w = map(int, input().split())
  s = [input() + '#' for _ in range(h)]
  s.append('#' * (w + 1))

  rt = [[-1] * (w + 1) for _ in range(h + 1)]

  tstart = [-1] * (w + 1)
  for i in range(h + 1):
    si = s[i]
    rti = rt[i]
    ystart = -1
    for j in range(w + 1):
      if si[j] == '#':
        if ystart != -1:
          jy = j - ystart
          for k in range(ystart, j):
            rti[k] += jy
          ystart = -1
        tj = tstart[j]
        if tj != -1:
          itj = i - tj
          for k in range(tj, i):
            rt[k][j] += itj
          tstart[j] = -1
      else:
        if ystart == -1:
          ystart = j
        if tstart[j] == -1:
          tstart[j] = i

  print(_max(_max(l) for l in rt))

main()

Submission status: Time Limit Exceeded

Solution code:
def main():
  _max = max
  h, w = map(int, input().split())
  s = [input() + '#' for _ in range(h)]
  s.append('#' * (w + 1))

  rt = [[-1] * w for _ in range(h)]

  tstart = [-1] * (w + 1)
  for i in range(h + 1):
    si = s[i]
    ystart = -1
    for j in range(w + 1):
      if si[j] == '#':
        if ystart != -1:
          for k in range(ystart, j):
            rt[i][k] += j - ystart
          ystart = -1
        if tstart[j] != -1:
          for k in range(tstart[j], i):
            rt[k][j] += i - tstart[j]
          tstart[j] = -1
      else:
        if ystart == -1:
          ystart = j
        if tstart[j] == -1:
          tstart[j] = i

  print(_max(_max(l) for l in rt))

main()

Submission status: Time Limit Exceeded

Solution code:
def main():
  h, w = map(int, input().split())
  s = [input() + '#' for _ in range(h)]
  s.append('#' * (w + 1))

  yoko = [[0] * w for _ in range(h)]
  tate = [[0] * w for _ in range(h)]

  tstart = [-1] * (w + 1)
  for i in range(h + 1):
    si = s[i]
    ystart = -1
    for j in range(w + 1):
      if si[j] == '#':
        if ystart != -1:
          for k in range(ystart, j):
            yoko[i][k] = j - ystart
          ystart = -1
        if tstart[j] != -1:
          for k in range(tstart[j], i):
            tate[k][j] = i - tstart[j]
          tstart[j] = -1
      else:
        if ystart == -1:
          ystart = j
        if tstart[j] == -1:
          tstart[j] = i

  result = 0
  for i in range(h):
    yokoi = yoko[i]
    tatei = tate[i]
    for j in range(w):
      t = yokoi[j] + tatei[j] - 1
      if t > result:
        result = t

  print(result)

main()

Submission status: Time Limit Exceeded

Solution code:
def main():
  h, w = map(int, input().split())
  s = [input() + '#' for _ in range(h)]
  s.append('#' * w)
  
  yoko = [[0] * w for _ in range(h)]
  for i in range(h):
    si = s[i]
    start = -1
    for j in range(w + 1):
      if si[j] == '#':
        if start != -1:
          for k in range(start, j):
            yoko[i][k] = j - start
          start = -1
      else:
        if start == -1:
          start = j
  
  tate = [[0] * w for _ in range(h)]
  for i in range(w):
    start = -1
    for j in range(h + 1):
      if s[j][i] == '#':
        if start != -1:
          for k in range(start, j):
            tate[k][i] = j - start
          start = -1
      else:
        if start == -1:
          start = j
  
  result = 0
  for i in range(h):
    yokoi = yoko[i]
    tatei = tate[i]
    for j in range(w):
      t = yokoi[j] + tatei[j] - 1
      if t > result:
        result = t
  
  print(result)

main()

Submission status: Time Limit Exceeded

Solution code:
h, w = map(int, input().split())
s = [input() + '#' for _ in range(h)]
s.append('#' * w)

yoko = [[0] * w for _ in range(h)]
for i in range(h):
  if s[i][0] == '.':
    start = 0
  else:
    start = -1
  for j in range(1, w + 1):
    if s[i][j] == '#':
      if start != -1:
        for k in range(start, j):
          yoko[i][k] = j - start
        start = -1
    else:
      if start == -1:
        start = j

tate = [[0] * w for _ in range(h)]
for i in range(w):
  if s[0][i] == '.':
    start = 0
  else:
    start = -1
  for j in range(1, h + 1):
    if s[j][i] == '#':
      if start != -1:
        for k in range(start, j):
          tate[k][i] = j - start
        start = -1
    else:
      if start == -1:
        start = j
result = 0
for i in range(h):
  for j in range(w):
    t = yoko[i][j] + tate[i][j] - 1
    if t > result:
      result = t

print(result)

Submission status: Time Limit Exceeded

Solution code:
h,w=[int(i) for i in input().split()]
check=[]
for i in range(h):
    check.append(input())
# print(check)

checkrow=[i.split("#") for i in check]

light=[[[0,0] for i in range(w)] for j in range(h)]
# print(light)

for i in range(h):
    head=0
    lightrow=light[i]
    for factor in checkrow[i]:
        length=len(factor)
        for j in range(length):
            lightrow[head+j][0]=length
        head+=length+1
        
# print(light)

checkreverse=[[None for i in range(h)] for i in range(w)]
for i in check:
    i=list(i)
for i in range(w):
    for j in range(h):
        checkreverse[i][j]=check[j][i]

for i in range(w):
    checkreverse[i]="".join(checkreverse[i])
    

# print(checkreverse)
checkrow=[i.split("#") for i in checkreverse]

for i in range(w):
    head=0
    for factor in checkrow[i]:
        length=len(factor)
        for j in range(length):
            light[head+j][i][1]=length
        head+=length+1
        
# print(light)
maxnum=0
for i in light:
    for j in i:
        num=j[0]+j[1]-1
        if num>maxnum:
            maxnum=num
print(maxnum)

Submission status: Time Limit Exceeded

Solution code:
h,w=[int(i) for i in input().split()]
check=[]
for i in range(h):
    check.append(input())
# print(check)

checkrow=[i.split("#") for i in check]

light=[[[0,0] for i in range(w)] for j in range(h)]
# print(light)

for i in range(h):
    head=0
    lightrow=light[i]
    for factor in checkrow[i]:
        length=len(factor)
        for j in range(length):
            lightrow[head+j][0]=length
        head+=length+1
        
# print(light)

checkreverse=["" for i in range(w)]
for j in range(w):
    for i in check:
        checkreverse[j]+=i[j]

# print(checkreverse)
checkrow=[i.split("#") for i in checkreverse]

for i in range(w):
    head=0
    for factor in checkrow[i]:
        length=len(factor)
        for j in range(length):
            light[head+j][i][1]=length
        head+=length+1
        
# print(light)
maxnum=0
for i in light:
    for j in i:
        num=j[0]+j[1]-1
        if num>maxnum:
            maxnum=num
print(maxnum)

Submission status: Time Limit Exceeded

Solution code:
h,w=[int(i) for i in input().split()]
check=[]
for i in range(h):
    check.append(input())
light=[[[0,0] for i in range(w)] for i in range(h)]

for i in range(h):
    head=1
    checkrow=check[i]
    lightrow=light[i]
    
    for j in range(w):
        if checkrow[j]=="#":
            head=1
        elif head==0:
            lightrow[j][0]=lightrow[j-1][0]
        else:
            a=j
            while a<w:
                if checkrow[a]==".":
                    lightrow[j][0]+=1
                    a+=1
                else:
                    break
            head=0
for i in range(w):
    head=1
    for j in range(h):
        if check[j][i]=="#":
            head=1
        elif head==0:
            light[j][i][1]=light[j-1][i][1]
        else:
            a=j
            while a<h:
                if check[a][i]==".":
                    light[j][i][1]+=1
                    a+=1
                else:
                    break
            head=0
maxnum=0                    
for i in light:
    for j in i:
        lightmin=j[0]+j[1]-1
        if maxnum<lightmin:
            maxnum=lightmin
print(maxnum)

Submission status: Time Limit Exceeded

Solution code:
import sys
stdin = sys.stdin
read_int = lambda : list(map(int,stdin.readline().split()))
H, W = read_int()

range_W = range(W)
range_H = range(H)
# nomal
L = [[0 for _ in range_W] for _ in range_H]
R = [[0 for _ in range_W] for _ in range_H]
U = [[0 for _ in range_W] for _ in range_H]
D = [[0 for _ in range_W] for _ in range_H]
res = [[0 for _ in range_W] for _ in range_H]
grid = []

append = grid.append
for i in range_H:
    row = list(" ".join(input()).split())
    append(row)

def solve():
    ans = 0
    for i in range_H:
        for j in range_W:
            if grid[i][j] == ".":
                L[i][j] = 1 if j == 0 else L[i][j - 1] + 1
                U[i][j] = 1 if i == 0 else U[i - 1][j] + 1
                res[i][j] += L[i][j] + U[i][j]
                ans = max(res[i][j], ans)

            if grid[H - i - 1][W - j - 1] == ".":
                R[H - i - 1][W - j - 1] = 1 if j == 0 else R[H - i - 1][W - j] + 1
                D[H - i - 1][W - j - 1] = 1 if i == 0 else D[H - i][W - j - 1] + 1
                res[H - i - 1][W - j - 1] += R[H - i - 1][W - j - 1] + D[H - i - 1][W - j - 1]
                ans = max(res[H - i - 1][W - j - 1], ans)
    return ans - 3

if __name__ == "__main__":
    print(solve())

Submission status: Time Limit Exceeded

Solution code:
# 定数
INF = float("inf")
MOD = int(1e9 + 7)

# エントリーポイント
def main():
    H, W = map(int, input().split())
    S = tuple(tuple(input()) for _ in range(H))

    hstage = []
    for n in range(H):
        line, c = [], 0
        for m in range(W):
            if S[n][m] == "#":
                line += [c] * c + [0]
                c = 0
            else:
                c += 1
        else:
            line += [c] * c
        hstage += [line]

    vstage = []
    for m in range(W):
        line, c = [], 0
        for n in range(H):
            if S[n][m] == "#":
                line += [c] * c + [0]
                c = 0
            else:
                c += 1
        else:
            line += [c] * c
        vstage += [line]

    max_lumps = 0
    for y in range(H):
        for x in range(W):
            if max_lumps < (hstage[y][x] + vstage[x][y] - 1):
                max_lumps = hstage[y][x] + vstage[x][y] - 1
    print(max_lumps)

main()

Submission status: Time Limit Exceeded

Solution code:
import sys
stdin = sys.stdin
read_int = lambda : list(map(int,stdin.readline().split()))
H, W = read_int()


# nomal
L = [[0 for _ in range(W)] for _ in range(H)]
R = [[0 for _ in range(W)] for _ in range(H)]
U = [[0 for _ in range(W)] for _ in range(H)]
D = [[0 for _ in range(W)] for _ in range(H)]
res = [[0 for _ in range(W)] for _ in range(H)]
grid = []

append = grid.append
for i in range(H):
    row = list(" ".join(input()).split())
    append(row)

def solve():
    ans = 0
    for i in range(H):
        for j in range(W):
            if grid[i][j] == ".":
                L[i][j] = 1 if j == 0 else L[i][j - 1] + 1
                U[i][j] = 1 if i == 0 else U[i - 1][j] + 1
                res[i][j] += L[i][j] + U[i][j]
                ans = max(res[i][j], ans)

            if grid[H - i - 1][W - j - 1] == ".":
                R[H - i - 1][W - j - 1] = 1 if j == 0 else R[H - i - 1][W - j] + 1
                D[H - i - 1][W - j - 1] = 1 if i == 0 else D[H - i][W - j - 1] + 1
                res[H - i - 1][W - j - 1] += R[H - i - 1][W - j - 1] + D[H - i - 1][W - j - 1]
                ans = max(res[H - i - 1][W - j - 1], ans)
    return ans - 3

if __name__ == "__main__":
    print(solve())