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:
h, w = map(int, raw_input().split())
S = [raw_input() for i in range(h)]
L = [[0]*w for i in range(h)]
R = [[0]*w for i in range(h)]
U = [[0]*w for i in range(h)]
D = [[0]*w for i in range(h)]

for i in range(h):
    ps = 0
    s = S[i]
    for j in range(w):
        if s[j] == "#":
            ps = 0
        else:
            ps += 1
            L[i][j] = ps

for j in range(w):
    ps = 0
    for i in range(h):
        if S[i][j] == "#":
            ps = 0
        else:
            ps += 1
            U[i][j] = ps

for i in range(h-1, -1, -1):
    ps = 0
    for j in range(w-1, -1, -1):
        if S[i][j] == "#":
            ps = 0
        else:
            ps += 1
            R[i][j] = ps
for j in range(w-1, -1, -1):
    ps = 0
    for i in range(h-1, -1, -1):
        if S[i][j] == "#":
            ps = 0
        else:
            ps += 1
            D[i][j] = ps
maxLight = 0
for i in range(h):
    for j in range(w):
        maxLight = max(maxLight, L[i][j] + R[i][j] + U[i][j] + D[i][j] - 3)
print maxLight

Submission status: Time Limit Exceeded

Solution code:
#ABC129D-Lamp.py

#import list
from sys import stdin, setrecursionlimit
from functools import lru_cache
import numpy as np

input = stdin.readline
setrecursionlimit(1000)

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

#variable

#function
#@lru_cache(maxsize=None)

#class

#main function
def main():
    L = np.zeros((H,W))
    R = np.zeros((H,W))
    U = np.zeros((H,W))
    D = np.zeros((H,W))

    for i in range(H):
        for j in range(W):
            if S[i][j] == "#":
                L[i,j] = 0
            elif S[i][j] == ".":
                if j == 0:
                    L[i,j] = 1
                else:
                    L[i,j] = L[i,j-1] + 1

            if S[i][W-j-1] == "#":
                R[i,W-j-1] = 0
            elif S[i][W-j-1] == ".":
                if j == 0:
                    R[i,W-j-1] = 1
                else:
                    R[i,W-j-1] = R[i,W-j] + 1

            if S[i][j] == "#":
                U[i,j] = 0
            elif S[i][j] == ".":
                if i == 0:
                    U[i,j] = 1
                else:
                    U[i,j] = U[i-1,j] + 1

            if S[H-i-1][j] == "#":
                D[H-i-1,j] = 0
            elif S[H-i-1][j] == ".":
                if i == 0:
                    D[H-i-1,j] = 1
                else:
                    D[H-i-1,j] = D[H-i,j] + 1

    maxScore = 0
    score = np.array([L[i,j]+R[i,j]+U[i,j]+D[i,j]-3 for i in range(H) for j in range(W)])
    #for i in range(H):
    #    for j in range(W):
    #        score = L[i,j]+R[i,j]+U[i,j]+D[i,j]-3
    #        if score > maxScore:
    #            maxScore = score
    print(int(score.max()))


if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
h, w = map(int, raw_input().split())
S = [[c for c in raw_input()] for i in range(h)]
Gh = [[0]*w for i in range(h)]
Gw = [[0]*w for i in range(h)]

for i in range(h):
    ps = 0
    s = S[i]
    for j in range(w):
        if w == j or s[j] == "#":
            ps = 0
        else:
            ps += 1
            Gh[i][j] = ps

for j in range(w):
    ps = 0
    for i in range(h):
        if i == h or S[i][j] == "#":
            ps = 0
        else:
            ps += 1
            Gw[i][j] = ps

for i in range(h-1, -1, -1):
    ps = 0
    for j in range(w-1, -1, -1):
        if S[i][j] == "#":
            ps = 0
        else:
            ps = max(ps, Gh[i][j])
            Gh[i][j] = ps
for j in range(w-1, -1, -1):
    ps = 0
    for i in range(h-1, -1, -1):
        if S[i][j] == "#":
            ps = 0
        else:
            ps = max(ps, Gw[i][j])
            Gw[i][j] = ps
maxLight = 0
for i in range(h):
    for j in range(w):
        maxLight = max(maxLight, Gh[i][j] + Gw[i][j]-1)
print maxLight

Submission status: Time Limit Exceeded

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

    matl = [[0 for _ in range(w)] for _ in range(h)]
    matr = [[0 for _ in range(w)] for _ in range(h)]
    matu = [[0 for _ in range(w)] for _ in range(h)]
    matd = [[0 for _ in range(w)] for _ in range(h)]

    for j in range(h):
        for i in range(w):
            if ss[j][i] == '#':
                matd[j][i] = 0
            elif j == 0:
                matd[j][i] = 1
            else:
                matd[j][i] = matd[j - 1][i] + 1

            if ss[h - j - 1][i] == '#':
                matu[h - j - 1][i] = 0
            elif h - j == h:
                matu[h - j - 1][i] = 1
            else:
                matu[h - j - 1][i] = matu[h - j][i] + 1

            if ss[j][i] == '#':
                matr[j][i] = 0
            elif i == 0:
                matr[j][i] = 1
            else:
                matr[j][i] = matr[j][i - 1] + 1

            if ss[j][w - i - 1] == '#':
                matl[j][w - i - 1] = 0
            elif w - i == w:
                matl[j][w - i - 1] = 1
            else:
                matl[j][w - i - 1] = matl[j][w - i] + 1

    maxv = 0
    for j in range(h):
        for i in range(w):
            tmp = matu[j][i] + matd[j][i] + matr[j][i] + matl[j][i]
            if tmp > maxv:
                maxv = tmp
    print(maxv - 3)

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
h, w = map(int, raw_input().split())
S = [[c for c in raw_input()] for i in range(h)]
Gh = [[0]*w for i in range(h)]
Gw = [[0]*w for i in range(h)]

for i in range(h):
    ps = 0
    leftObstacle = -1
    s = S[i]
    for j in range(w+1):
        if w == j or s[j] == "#":
            for k in range(leftObstacle + 1, j):
                Gh[i][k] = ps
            ps = 0
            leftObstacle = j
        else:
            ps += 1

for j in range(w):
    ps = 0
    upObstacle = -1
    for i in range(h+1):
        if i == h or S[i][j] == "#":
            for k in range(upObstacle+1, i):
                Gw[k][j] = ps
            ps = 0
            upObstacle = i
        else:
            ps += 1
maxLight = 0
for i in range(h):
    for j in range(w):
        maxLight = max(maxLight, Gh[i][j] + Gw[i][j]-1)
print maxLight

Submission status: Time Limit Exceeded

Solution code:
2324
668
3648
182432
8168126


H, W = map(int, input().split())
S_list = [None] * H

for h in range(H):
    input_str = list(input())
    S_list[h] = [0 if char == '#' else 1 for char in input_str]


l_list = [[0] * W for _ in range(H)]
r_list = [[0] * W for _ in range(H)]
d_list = [[0] * W for _ in range(H)]
u_list = [[0] * W for _ in range(H)]
for h in range(H):
    for w in range(W):
        left_index = w
        right_index = W - w - 1
        up_index = h
        down_index = H - h - 1

        #left
        if left_index == 0:
            l_list[h][left_index] = S_list[h][left_index]
        else:
            l_list[h][left_index] = (l_list[h][left_index - 1] + 1) * S_list[h][left_index]

        #right
        if right_index == W - 1:
            r_list[h][right_index] = S_list[h][right_index]
        else:
            r_list[h][right_index] = (r_list[h][right_index + 1] + 1) * S_list[h][right_index]

        #up
        if up_index == 0:
            u_list[up_index][w] = S_list[up_index][w]
        else:
            u_list[up_index][w] = (u_list[up_index - 1][w] + 1) * S_list[up_index][w]

        #down
        if down_index == H - 1:
            d_list[down_index][w] = S_list[down_index][w]
        else:
            d_list[down_index][w] = (d_list[down_index + 1][w] + 1) * S_list[down_index][w]


max_light = 0
for h in range(H):
    for w in range(W):
        lights = l_list[h][w] + r_list[h][w] + u_list[h][w] + d_list[h][w] - 3
        max_light = max(max_light, lights)

print(max_light)

Submission status: Time Limit Exceeded

Solution code:
from collections import defaultdict
from collections import deque
from string import ascii_uppercase
import sys, bisect, math, heapq
stdin = sys.stdin
read_int = lambda : list(map(int,stdin.readline().split()))
read_str = lambda : stdin.readline().rstrip()

H, W = read_int()
grid = []
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)]

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

res = [[-3 for _ in range(W)] for _ in range(H)]

def solve():
    ans = 0
    for i in range(H):
        for j in range(W):
            if grid[i][j] == "#":
                L[i][j] = U[i][j] = 0
            else:
                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] = D[H - i - 1][W - j - 1] = 0
            else:
                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

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

Submission status: Time Limit Exceeded

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

M_W = [[0] * W for i in range(H)]
M_H = [[0] * W for i in range(H)]

for i in range(H):
  for j in range(W):
    if S[i][j] == '.':
      if j == 0:
        M_W[i][j] = 1
      else:
        M_W[i][j] = M_W[i][j - 1] + 1
    else:
      M_W[i][j] = 0

for i in range(H):
  max_num = 0
  for j in range(W - 1, -1, -1):
    if M_W[i][j] != 0:
      max_num = max(max_num, M_W[i][j])
      M_W[i][j] = max_num
    else:
      max_num = 0

for j in range(W):
  for i in range(H):
    if S[i][j] == '.':
      if i == 0:
        M_H[i][j] = 1
      else:
        M_H[i][j] = M_H[i - 1][j] + 1
    else:
      M_H[i][j] = 0

for j in range(W):
  max_num = 0
  for i in range(H - 1, -1, -1):
    if M_H[i][j] != 0:
      max_num = max(max_num, M_H[i][j])
      M_H[i][j] = max_num
    else:
      max_num = 0

ans = 0
for i in range(H):
  for j in range(W):
    ans = max(ans, M_W[i][j] + M_H[i][j] -1)
print(ans)

Submission status: Time Limit Exceeded

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

M_W = [[0] * W for i in range(H)]
M_H = [[0] * W for i in range(H)]

for i in range(H):
  for j in range(W):
    if S[i][j] == '.':
      if j == 0:
        M_W[i][j] = 1
      else:
        M_W[i][j] = M_W[i][j - 1] + 1
    else:
      M_W[i][j] = 0

for i in range(H):
  max_num = 0
  for j in range(W - 1, -1, -1):
    if M_W[i][j] != 0:
      max_num = max(max_num, M_W[i][j])
      M_W[i][j] = max_num
    else:
      max_num = 0

for j in range(W):
  for i in range(H):
    if S[i][j] == '.':
      if i == 0:
        M_H[i][j] = 1
      else:
        M_H[i][j] = M_H[i - 1][j] + 1
    else:
      M_H[i][j] = 0

for j in range(W):
  max_num = 0
  for i in range(H - 1, -1, -1):
    if M_H[i][j] != 0:
      max_num = max(max_num, M_H[i][j])
      M_H[i][j] = max_num
    else:
      max_num = 0

ans = 0
for i in range(H):
  for j in range(W):
    ans = max(ans, M_W[i][j] + M_H[i][j] -1)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
from collections import defaultdict
from collections import deque
from string import ascii_uppercase
import sys, bisect, math
stdin = sys.stdin
read_int = lambda : list(map(int,stdin.readline().split()))
read_str = lambda : stdin.readline().rstrip()

H, W = read_int()
grid = []
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)]

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

res = [[0 for _ in range(W)] for _ in range(H)]
def solve():
    ans = 0
    for i in range(H):
        for j in range(W):
            if grid[i][j] == "#":
                L[i][j] = U[i][j] = 0
            else:
                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

            if grid[H - i - 1][W - j - 1] == "#":
                R[H - i - 1][W - j - 1] = D[H - i - 1][W - j - 1] = 0
            else:
                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

    for i in range(H):
        for j in range(W):
            ans = max(L[i][j] + R[i][j] + U[i][j] + D[i][j] - 3, ans)

    return ans

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

Submission status: Time Limit Exceeded

Solution code:
H, W = map(int, input().split())
S = [list(input()) for _ in range(H)]
r = [[0 for _ in range(W)] for _ in range(H)]
l = [[0 for _ in range(W)] for _ in range(H)]
d = [[0 for _ in range(W)] for _ in range(H)]
u = [[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] == ".":
            r[i][j] = c
            c += 1
        else:
            c = 0
for i in range(H):
    c = 0
    for j in range(W)[::-1]:
        if S[i][j] == ".":
            c += 1
            l[i][j] = c
        else:
            c = 0
for i in range(W):
    c = 0
    for j in range(H):
        if S[j][i] == ".":
            d[j][i] = c
            c += 1
        else:
            c = 0
for i in range(W):
    c = 0
    for j in range(H)[::-1]:
        if S[j][i] == ".":
            c += 1
            u[j][i] = c
        else:
            c = 0
ans = 0
for i in range(H):
    for j in range(W):
        ans = max(ans, r[i][j] + l[i][j] + d[i][j] + u[i][j] - 1)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
h,w = map(int, input().split())
Data = [[[0,0,0,0] for i in range(w)] for j in range(h)]
S = [input() for i in range(h)]
for i in range(h):
    for j in range(w):
        if S[i][j] == ".":
            if j > 0:
                Data[i][j][0] = Data[i][j-1][0] + 1
            else:
                Data[i][j][0] = 1
    for j in range(w-1,-1,-1):
        if S[i][j] == ".":
            if j < w-1:
                Data[i][j][1] = Data[i][j+1][1] + 1
            else:
                Data[i][j][1] = 1
for i in range(w):
    for j in range(h):
        if S[j][i] == ".":
            if j > 0:
                Data[j][i][2] = Data[j-1][i][2] + 1
            else:
                Data[j][i][2] = 1
    for j in range(h-1,-1,-1):
        if S[j][i] == ".":
            if j < h-1:
                Data[j][i][3] = Data[j+1][i][3] + 1
            else:
                Data[j][i][3] = 1
ans = 0
for i in range(h):
    for j in range(w):
       ans = max(sum(Data[i][j])-3,ans)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
h,w = map(int, input().split())
Data = [[[0,0,0,0] for i in range(w)] for j in range(h)]
S = [input() for i in range(h)]
for i in range(h):
    for j in range(w):
        if S[i][j] == ".":
            if j > 0:
                Data[i][j][0] = Data[i][j-1][0] + 1
            else:
                Data[i][j][0] = 1
for i in range(h):
    for j in range(w-1,-1,-1):
        if S[i][j] == ".":
            if j < w-1:
                Data[i][j][1] = Data[i][j+1][1] + 1
            else:
                Data[i][j][1] = 1
for i in range(w):
    for j in range(h):
        if S[j][i] == ".":
            if j > 0:
                Data[j][i][2] = Data[j-1][i][2] + 1
            else:
                Data[j][i][2] = 1
for i in range(w):
    for j in range(h-1,-1,-1):
        if S[j][i] == ".":
            if j < h-1:
                Data[j][i][3] = Data[j+1][i][3] + 1
            else:
                Data[j][i][3] = 1
ans = 0
for i in range(h):
    for j in range(w):
       ans = max(sum(Data[i][j])-3,ans)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
H, W = map(int, input().split())
S_list = [None] * H

for h in range(H):
    S_list[h] = list(input())


l_list = [[0] * W for _ in range(H)]
r_list = [[0] * W for _ in range(H)]
d_list = [[0] * W for _ in range(H)]
u_list = [[0] * W for _ in range(H)]
for h in range(H):
    for w in range(W):
        left_index = w
        right_index = W - w - 1
        up_index = h
        down_index = H - h - 1

        #left
        if S_list[h][left_index] != '#':
            if left_index == 0:
                l_list[h][left_index] = 1
            else:
                l_list[h][left_index] = l_list[h][left_index - 1] + 1

        #right
        if S_list[h][right_index] != '#':
            if right_index == W - 1:
                r_list[h][right_index] = 1
            else:
                r_list[h][right_index] = r_list[h][right_index + 1] + 1

        #up
        if S_list[up_index][w] != '#':
            if up_index == 0:
                u_list[up_index][w] = 1
            else:
                u_list[up_index][w] = u_list[up_index - 1][w] + 1

        #down
        if S_list[down_index][w] != '#':
            if down_index == H - 1:
                d_list[down_index][w] = 1
            else:
                d_list[down_index][w] = d_list[down_index + 1][w] + 1


max_right = 0
for h in range(H):
    for w in range(W):
        rights = l_list[h][w] + r_list[h][w] + u_list[h][w] + d_list[h][w] - 3
        max_right = max(max_right, rights)

print(max_right)

Submission status: Time Limit Exceeded

Solution code:
H, W = map(int, input().split())
S_list = [None] * H

for h in range(H):
    S_list[h] = list(input())


l_list = [[0] * W for _ in range(H)]
r_list = [[0] * W for _ in range(H)]
d_list = [[0] * W for _ in range(H)]
u_list = [[0] * W for _ in range(H)]
for h in range(H):
    #left
    for w in range(W):
        if S_list[h][w] == '#':
            continue
        elif w == 0:
            l_list[h][w] = 1
        else:
            l_list[h][w] = l_list[h][w - 1] + 1
    #right
    for w in reversed(range(W)):
        if S_list[h][w] == '#':
            continue
        elif w == W - 1:
            r_list[h][w] = 1
        else:
            r_list[h][w] = r_list[h][w + 1] + 1

for w in range(W):
    #up
    for h in range(H):
        if S_list[h][w] == '#':
            continue
        elif h == 0:
            u_list[h][w] = 1
        else:
            u_list[h][w] = u_list[h - 1][w] + 1
    #down
    for h in reversed(range(H)):
        if S_list[h][w] == '#':
            continue
        elif h == H - 1:
            d_list[h][w] = 1
        else:
            d_list[h][w] = d_list[h + 1][w] + 1


max_right = 0
for h in range(H):
    for w in range(W):
        rights = l_list[h][w] + r_list[h][w] + u_list[h][w] + d_list[h][w] - 3
        max_right = max(max_right, rights)

print(max_right)

Submission status: Time Limit Exceeded

Solution code:
H, W = map(int, input().split())
S = [0 for i in range(H)]
for i in range(H):
    S[i] = input()
#print(T)
yokol = [[0 for j in range(W)] for i in range(H)]
yokor = [[0 for j in range(W)] for i in range(H)]
tatel = [[0 for j in range(W)] for i in range(H)]
tater = [[0 for j in range(W)] for i in range(H)]
for i in range(H):
    for j in range(W):
        if S[i][j] == '#':
            pass
        else:
            if j >= 1:
                tatel[i][j] = tatel[i][j-1] + 1
            else:
                tatel[i][j] = 1
            if i >= 1:
                yokol[i][j] = yokol[i-1][j] + 1
            else:
                yokol[i][j] = 1
        if S[i][W-j-1] == '#':
            pass
        else:
            if j >= 1:
                tater[i][W-j-1] = tater[i][W-j] + 1
            else:
                tater[i][W-j-1] = 1
        if S[H-i-1][j] == '#':
            pass
        else:
            if i >= 1:
                yokor[H-i-1][j] = yokor[H-i][j] + 1
            else:
                yokor[H-i-1][j] = 1
#print(tatel)
#print(tater)
#print(yokol)
#print(yokor)



maxdp = 0
for i in range(H):
    for j in range(W):
        maxdp = max(maxdp, tatel[i][j] + tater[i][j] +yokol[i][j] + yokor[i][j] -3)
print(maxdp)

#print(yoko)
#print(tate)

Submission status: Time Limit Exceeded

Solution code:
H, W = map(int, input().split())
S = [0 for i in range(H)]
for i in range(H):
    S[i] = input()
T = ['' for j in range(W)]
for j in range(W):
    for i in range(H):
        T[j] += S[i][j]
#print(T)
yokol = [[0 for j in range(W)] for i in range(H)]
yokor = [[0 for j in range(W)] for i in range(H)]
tatel = [[0 for j in range(W)] for i in range(H)]
tater = [[0 for j in range(W)] for i in range(H) ]
for i in range(H):
    for j in range(W):
        if S[i][j] == '#':
            pass
        else:
            if j >= 1:
                tatel[i][j] = tatel[i][j-1] + 1
            else:
                tatel[i][j] = 1
        if S[i][W-j-1] == '#':
            pass
        else:
            if j >= 1:
                tater[i][W-j-1] = tater[i][W-j] + 1
            else:
                tater[i][W-j-1] = 1
#print(tatel)
#print(tater)



for j in range(W):
    for i in range(H):
        if T[j][i] == '#':
            pass
        else:
            if i >= 1:
                yokol[i][j] = yokol[i-1][j] + 1
            else:
                yokol[i][j] = 1
        if T[j][H - i -1] == '#':
            pass
        else:
            if i >= 1:
                yokor[H-i-1][j] = yokor[H-i][j] + 1
            else:
                yokor[H-i-1][j] = 1
#print(yokol)
#print(yokor)



maxdp = 0
for i in range(H):
    for j in range(W):
        maxdp = max(maxdp, tatel[i][j] + tater[i][j] +yokol[i][j] + yokor[i][j] -3)
print(maxdp)

#print(yoko)
#print(tate)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
h,w = map(int,input().split())
s = []
s.append("_"*(w+2))
for i in range(h):
    s.append("|"+ input() + "|")
s.append("_"*(w+2))

c = np.array(s)
ansl = 0 
for i in range(h):
    for j in range(w):
        if c[1+i][1+j] == ".":
            ans = 0
            k=1
            while c[1+i+k][1+j] == ".":
                k += 1
                ans +=1
            k=1
            while c[1+i-k][1+j] == ".":
                k += 1
                ans +=1
            k=1
            while c[1+i][1+j+k] == ".":
                k += 1
                ans +=1
            k=1
            while c[1+i][1+j-k] == ".":
                k += 1
                ans +=1
            if ans > ansl:
                ansl = ans
            
print(ansl + 1)

Submission status: Time Limit Exceeded

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

ansl = 0 
for i in range(h):
    for j in range(w):
        if s[1+i][1+j] == ".":
            ans = 0
            k=1
            while s[1+i+k][1+j] == ".":
                k += 1
                ans +=1
            k=1
            while s[1+i-k][1+j] == ".":
                k += 1
                ans +=1
            k=1
            while s[1+i][1+j+k] == ".":
                k += 1
                ans +=1
            k=1
            while s[1+i][1+j-k] == ".":
                k += 1
                ans +=1
            if ans > ansl:
                ansl = ans
            
print(ansl + 1)

Submission status: Time Limit Exceeded

Solution code:
h, w = map(int, input().split())
s = [list(input()) for i in range(h)]
ans = 0
for i in range(h):
    for j in range(w):
        if s[i][j]==".":
            up = 0
            while True:
                try:
                    if i<up: break
                    if s[i-up][j]==".": up+=1
                    else: break
                except: break
            down = 0
            while True:
                try:
                    if s[i+down][j]==".": down+=1
                    else: break
                except: break
            right = 0
            while True:
                try:
                    if s[i][j+right]==".": right+=1
                    else: break
                except: break
            left = 0
            while True:
                try:
                    if j<left: break
                    if s[i][j-left]==".": left+=1
                    else: break
                except: break
            #print(up, down, right, left)
            ans = max(ans, up+down+right+left-3)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

H, W = map(int, input().split())

SS = []

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)]

SS = []
for h in range(H):
    S = input()
    SS.append(S)
    for w in range(W):
        if w != 0:
            if SS[h][w] != '#':
                if SS[h][w-1] == '#':
                    L[h][w] = 0
                else:
                    L[h][w] = L[h][w-1] + 1

        if h != 0:
            if SS[h][w] != '#':
                if SS[h-1][w] == '#':
                    U[h][w] = 0
                else:
                    U[h][w] = U[h-1][w] + 1

    for w in range(W)[::-1]:
        if w != W - 1:
            if SS[h][w] != '#':
                if SS[h][w+1] == '#':
                    R[h][w] = 0
                else:
                    R[h][w] = R[h][w+1] + 1

for w in range(W):
    for h in range(H)[::-1]:
        if h != H - 1:
            if SS[h][w] != '#':
                if SS[h+1][w] == '#':
                    D[h][w] = 0
                else:
                    D[h][w] = D[h+1][w] + 1

max_light_up = 0
for w in range(W):
    for h in range(H)[::-1]:
        if h != H - 1:
            if SS[h][w] != '#':
                if SS[h+1][w] == '#':
                    D[h][w] = 0
                else:
                    D[h][w] = D[h+1][w] + 1

        if SS[h][w] == '#':
            light_up = L[h][w] + R[h][w] + U[h][w] + D[h][w]
        else:
            light_up = L[h][w] + R[h][w] + U[h][w] + D[h][w] + 1
        max_light_up = max(max_light_up, light_up)

print(max_light_up)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

H, W = map(int, input().split())

SS = []
for _ in range(H):
    S = input()
    SS.append(S)

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)]

for h in range(H):
    for w in range(W):
        if w != 0:
            if SS[h][w] != '#':
                if SS[h][w-1] == '#':
                    L[h][w] = 0
                else:
                    L[h][w] = L[h][w-1] + 1

for h in range(H):
    for w in range(W)[::-1]:
        if w != W - 1:
            if SS[h][w] != '#':
                if SS[h][w+1] == '#':
                    R[h][w] = 0
                else:
                    R[h][w] = R[h][w+1] + 1

for w in range(W):
    for h in range(H):
        if h != 0:
            if SS[h][w] != '#':
                if SS[h-1][w] == '#':
                    U[h][w] = 0
                else:
                    U[h][w] = U[h-1][w] + 1

for w in range(W):
    for h in range(H)[::-1]:
        if h != H - 1:
            if SS[h][w] != '#':
                if SS[h+1][w] == '#':
                    D[h][w] = 0
                else:
                    D[h][w] = D[h+1][w] + 1

max_light_up = 0
for h in range(H):
    for w in range(W):
        if SS[h][w] == '#':
            light_up = L[h][w] + R[h][w] + U[h][w] + D[h][w]
        else:
            light_up = L[h][w] + R[h][w] + U[h][w] + D[h][w] + 1
        max_light_up = max(max_light_up, light_up)

print(max_light_up)

Submission status: Time Limit Exceeded

Solution code:
inf = input().split()
H = int(inf[0])
W = int(inf[1])
sheet = [[] for i in range(H+2)]
score = [[] for i in range(H+2)]
m = 0
 
for h in range(H+2):
  if h==0 or h==H+1:
    a = [False]*(W+2)
    b = [(0,0)]*(W+2)
    sheet[h]=a
    score[h]=b
  else:
    line = input()
    a = []
    b = []
    a += [False]
    b += [(0,0)]
    for w in range(W):
      b+=[(0,0)]
      if line[w]=='.':
        a += [True]
      else:
        a += [False]
    a += [False]
    b += [(0,0)]
    sheet[h]=a
    score[h]=b
      
for h in range(1,H+1):
  for w in range(1,W+1):
    if sheet[h][w]:
      s = 0
      hs = 0
      ws = 0
      if sheet[h-1][w]:
        hs += score[h-1][w][0]
      else:
        i = h+1
        while sheet[i][w]:
          hs+=1
          i+=1
      if sheet[h][w-1]:
        ws += score[h][w-1][1]
      else:
        j = w+1
        while sheet[h][j]:
          ws+=1
          j+=1
      s = 1 + hs + ws
      score[h][w]=(hs, ws)
      if m < s:
        m = s
print(m)

Submission status: Time Limit Exceeded

Solution code:
inf = input().split()
H = int(inf[0])
W = int(inf[1])
dic = {}
score = {}
m = 0
 
for h in range(H+2):
  if h==0 or h==H+1:
    for w in range(W+2):
      dic[(h,w)] = False
      score[(h,w)] = (0,0)
  else:
    line = input()
    dic[(h,0)] = False
    dic[(h,W+1)] = False
    score[(h,0)] = (0,0)
    score[(h, w+1)] = (0,0)
    for w in range(W):
      if line[w]=='.':
        dic[(h,w+1)] = True
      else:
        dic[(h,w+1)] = False
      
for h in range(1,H+1):
  for w in range(1,W+1):
    score[(h,w)]=(0,0)
    if dic[(h,w)]:
      s = 0
      hs = 0
      ws = 0
      if dic[(h-1,w)]:
        s += score[(h-1,w)][0]
        hs += score[(h-1,w)][0]
      else:
        i = h+1
        while dic[(i,w)]:
          s+=1
          hs+=1
          i+=1
      if dic[(h, w-1)]:
        s += score[(h, w-1)][1]
        ws += score[(h,w-1)][1]
      else:
        j = w+1
        while dic[(h,j)]:
          s+=1
          ws+=1
          j+=1
      s+=1
      score[(h,w)]=(hs, ws)
      if m < s:
        m = s
print(m)