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, input().split())
data = []
for i in range(h):
    s = input()
    data.append(s)
cnt_l, cnt_r, cnt_u, cnt_d = [[0] * w for _ in range(h)], [[0] * w for _ in range(h)], [[0] * w for _ in range(h)], [[0] * w for _ in range(h)]

for i in range(h):
    for j in range(w):
        if data[i][j] == "#":
            cnt_l[i][j] = 0
        else:
            cnt_l[i][j] = cnt_l[i][j - 1] + 1
    
    for j in range(w - 1, -1, -1):
        if data[i][j] == "#":
            cnt_r[i][j] = 0
        else:
            if j == w - 1:
                cnt_r[i][j] = 1
            else:
                cnt_r[i][j] = cnt_r[i][j + 1] + 1

for j in range(w):
    for i in range(h):
        if data[i][j] == "#":
            cnt_u[i][j] = 0
        else:
            cnt_u[i][j] = cnt_u[i - 1][j] + 1
    
    for i in range(h - 1, -1, -1):
        if data[i][j] == "#":
            cnt_d[i][j] = 0
        else:
            if i == h - 1:
                cnt_d[i][j] = 1
            else:
                cnt_d[i][j] = cnt_d[i + 1][j] + 1

ans = 0
for i in range(h):
    for j in range(w):
        total= cnt_l[i][j] + cnt_r[i][j] + cnt_u[i][j] + cnt_d[i][j] - 3
        ans = max(ans, total)

print(ans)

Submission status: Time Limit Exceeded

Solution code:
h, w = map(int, input().split())
data = []
for i in range(h):
    s = input()
    data.append(s)
cnt_l, cnt_r, cnt_u, cnt_d = [[0] * w for _ in range(h)], [[0] * w for _ in range(h)], [[0] * w for _ in range(h)], [[0] * w for _ in range(h)]

for i in range(h):
    for j in range(w):
        if data[i][j] == "#":
            cnt_l[i][j] = 0
        else:
            cnt_l[i][j] = cnt_l[i][j - 1] + 1
    
    for j in range(w - 1, -1, -1):
        if data[i][j] == "#":
            cnt_r[i][j] = 0
        else:
            if j == w - 1:
                cnt_r[i][j] = 1
            else:
                cnt_r[i][j] = cnt_r[i][j + 1] + 1

for j in range(w):
    for i in range(h):
        if data[i][j] == "#":
            cnt_u[i][j] = 0
        else:
            cnt_u[i][j] = cnt_u[i - 1][j] + 1
    
    for i in range(h - 1, -1, -1):
        if data[i][j] == "#":
            cnt_d[i][j] = 0
        else:
            if i == h - 1:
                cnt_d[i][j] = 1
            else:
                cnt_d[i][j] = cnt_d[i + 1][j] + 1
cnt = [[0] * w for _ in range(h)]

ans = 0
for i in range(h):
    for j in range(w):
        cnt[i][j] = cnt_l[i][j] + cnt_r[i][j] + cnt_u[i][j] + cnt_d[i][j] - 3
        ans = max(ans, max(cnt[i]))

print(ans)

Submission status: Time Limit Exceeded

Solution code:
h, w = map(int, input().split())
data = []

for i in range(h):
    s = input()
    data.append(s)

ans = 0

def search_x(i, j, x):
    res = 0
    plus = x
    while (j - x >= 0 and j - x < w) and data[i][j - x] == ".":
        res += 1
        x += plus
    return res

def search_y(i, j, y):
    res = 0
    plus = y
    while (i - y >= 0 and i - y < h) and data[i - y][j] == ".":
        res += 1
        y += plus
    return res


for i in range(h):
    for j in range(w):
        if data[i][j] != "#":
            ans = max(ans, search_x(i, j, -1) + search_x(i, j, 1) + search_y(i, j, -1) + search_y(i, j, 1))

print(ans + 1)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
H, W = map(int, input().split())
S = np.zeros((H,W))
for i in range(H):
    Si = np.array([ 0 if s == '.' else 1 for s in input()])
    S[i] = Si

column_max_spaces = np.zeros(H)
for i in range(H):
    max_count = 0
    _count = 0
    for j in range(W):
        if S[i,j] == 0:
            _count += 1
        else:
            if _count > max_count:
                max_count = _count
            _count = 0
    else:
        if _count > max_count:
            max_count = _count
    column_max_spaces[i] = max_count

row_max_spaces = np.zeros(W)
for j in range(W):
    max_count = 0
    _count = 0
    for i in range(H):
        if S[i,j] == 0:
            _count += 1
        else:
            if _count > max_count:
                max_count = _count
            _count = 0
    else:
        if _count > max_count:
            max_count = _count
    row_max_spaces[j] = max_count

print(int(np.max(column_max_spaces) + np.max(row_max_spaces) - 1))

Submission status: Time Limit Exceeded

Solution code:
import bisect, collections, copy, heapq, itertools, math, string, sys
input = lambda: sys.stdin.readline().rstrip() 
sys.setrecursionlimit(10**7)
INF = float('inf')
def I(): return int(input())
def F(): return float(input())
def SS(): return input()
def LI(): return [int(x) for x in input().split()]
def LI_(): return [int(x)-1 for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LSS(): return input().split()

def resolve():
    H, W = LI()
    S = [list(SS()) for _ in range(H)]

    left = [[0] * W for _ in range(H)]
    for i in range(H):
        cnt = 0
        for j in range(W):
            if S[i][j] == '.':
                cnt += 1
                left[i][j] = cnt
            else:
                cnt = 0

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

    up = [[0] * W for _ in range(H)]
    for i in range(W):
        cnt = 0
        for j in range(H):
            if S[j][i] == '.':
                cnt += 1
                up[j][i] = cnt
            else:
                cnt = 0

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

    ans = [[0] * W for _ in range(H)]
    for i in range(H):
        for j in range(W):
            ans[i][j] = left[i][j] + right[i][j] + up[i][j] + down[i][j] - 3

    print(max([max(i) for i in ans]))

if __name__ == '__main__':
    resolve()

Submission status: Time Limit Exceeded

Solution code:
import bisect, collections, copy, heapq, itertools, math, string, sys
input = lambda: sys.stdin.readline().rstrip() 
sys.setrecursionlimit(10**7)
INF = float('inf')
def I(): return int(input())
def F(): return float(input())
def SS(): return input()
def LI(): return [int(x) for x in input().split()]
def LI_(): return [int(x)-1 for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LSS(): return input().split()

def resolve():
    H, W = LI()
    S = [list(SS()) for _ in range(H)]

    idx_w = []
    for i in range(H):
        tmp = [-1]
        for j in range(W):
            if S[i][j] == '#':
                tmp.append(j)
        tmp.append(W)
        idx_w.append(tmp)

    idx_h = []
    for i in range(W):
        tmp = [-1]
        for j in range(H):
            if S[j][i] == '#':
                tmp.append(j)
        tmp.append(H)
        idx_h.append(tmp)

    ans = [[0] * W for _ in range(H)]
    for i in range(H):
        for j in range(len(idx_w[i]) - 1):
            for k in range(idx_w[i][j] + 1, idx_w[i][j+1]):
                ans[i][k] += idx_w[i][j+1] - idx_w[i][j] - 1

    for i in range(W):
        for j in range(len(idx_h[i]) - 1):
            for k in range(idx_h[i][j] + 1, idx_h[i][j+1]):
                ans[k][i] += idx_h[i][j+1] - idx_h[i][j] - 2

    # for i in ans:
    #     print(i)

    print(max([max(i) for i in ans]))

if __name__ == '__main__':
    resolve()

Submission status: Time Limit Exceeded

Solution code:
import sys
input = sys.stdin.readline

H,W = (int(x) for x in input().rstrip('\n').split())
m = []
score = []
for i in range(H):
  m.append(list(input().rstrip('\n')))
def U(x,y):
  res = 0
  for i in range(y,-1,-1):
    if m[i][x]=='.':
      res += 1
    else:
      break
  return res
def D(x,y):
  res = 0
  for i in range(y,H):
    if m[i][x]=='.':
      res += 1
    else:
      break
  return res
def R(x,y):
  res = 0
  for i in range(x,W):
    if m[y][i]=='.':
      res += 1
    else:
      break
  return res
def L(x,y):
  res = 0
  for i in range(x,-1,-1):
    if m[y][i]=='.':
      res += 1
    else:
      break
  return res
for x in range(W):
  for y in range(H):
    res = 0
    res += U(x,y)
    res += D(x,y)
    res += L(x,y)
    res += R(x,y)
    res -= 3
    score.append(res)
print(max(score))

Submission status: Time Limit Exceeded

Solution code:
h,w=map(int,input().split())
l=list()
l.append('#'*(w+2))
for i in range(h):
    l.append("#"+input()+"#")
l.append('#'*(w+2))
si=[[0 for i in j] for j in l]
sj=[[0 for i in j] for j in l]
for i in range(h+2):
    k=0
    for j in range(w+2):
        if l[i][j]==".":
            k+=1
        else:
            for f in range(j-k,j):
                si[i][f]=k
            k=0
for j in range(w+2):
    k=0
    for i in range(h+2):
        if l[i][j]==".":
            k+=1
        else:
            for f in range(i-k,i):
                sj[f][j]=k
            k=0
ans=0
for i in range(h+2):
    for j in range(w+2):
        ans=max(ans,sj[i][j]+si[i][j])
print(ans-1)

Submission status: Time Limit Exceeded

Solution code:
H, W = map(int, input().split())
S = []
for i in range(H):
    S.append(input())
    
ans_W = [[-1 for i in range(W)] for j in range(H)]
for i in range(H):
    count = 0
    now = 0
    for j in range(W):
        if S[i][j] == ".":
            count += 1
        else:
            for k in range(now, min(W, now+1+count)):
                if k == j:
                    ans_W[i][k] = 0
                else:
                    ans_W[i][k] = count
            now += count+1
            count = 0
    if count != 0:
        for k in range(now, min(W, now+1+count)):
            ans_W[i][k] = count

ans_H = [[-1 for i in range(W)] for j in range(H)]
for i in range(W):
    count = 0
    now = 0
    for j in range(H):
        if S[j][i] == ".":
            count += 1
        else:
            for k in range(now, min(H, now+1+count)):
                if k == j:
                    ans_H[k][i] = 0
                else:
                    ans_H[k][i] = count
            now += count+1
            count = 0
    if count != 0:
        for k in range(now, min(H, now+1+count)):
            ans_H[k][i] = count

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

Submission status: Time Limit Exceeded

Solution code:
from collections import deque
H,W = map(int, input().split())
Ss = [str(input()) for _ in range(H)]

directions = [[-1,0],
              [0,-1],
              [1,0],
              [0,1]]

answer = 0
import copy
for i in range(H):
    for j in range(W):
        if Ss[i][j]==".":
            todo = deque([[i,j]])
        else:
            continue
        candidate = 0
        while len(todo) > 0:
            base = todo.pop()
            candidate += 1
            
            for direction in directions:
                checking = copy.deepcopy(base)
                for k in range(max(H,W)):
                    checking = [checking[0]+direction[0],checking[1]+direction[1]]
                    if checking[0] < 0 or checking[0] >= H or checking[1] < 0 or checking[1] >= W:
                        break
                    if Ss[checking[0]][checking[1]] == "#":
                        break
                    candidate += 1
        if candidate > answer:
            answer = candidate
print(answer)

Submission status: Time Limit Exceeded

Solution code:
def solve():
  ans = 0
  H, W = map(int, input().split())
  S = [0]*(H+2)
  S[0] = '*'*(W+2)
  S[H+1] = '*'*(W+2)
  for h in range(1,H+1):
    S[h] = '*' + input() + '*'
  L = [[0]*(W+2) for _ in range(H+2)]
  R = [[0]*(W+2) for _ in range(H+2)]
  U = [[0]*(W+2) for _ in range(H+2)]
  D = [[0]*(W+2) for _ in range(H+2)]
  for h in range(1,H+2):
    for w in range(1,W+2):
      if S[h][w]=='.':
        if S[h][w-1]=='.':
          L[h][w] = L[h][w-1]+1
        if S[h-1][w]=='.':
          U[h][w] = U[h-1][w]+1
  for h in range(H+1,0,-1):
    for w in range(W+1,0,-1):
      if S[h][w]=='.':
        if S[h][w+1]=='.':
          R[h][w] = R[h][w+1]+1
        if S[h+1][w]=='.':
          D[h][w] = D[h+1][w]+1
  total = [[0]*(W+2) for _ in range(H+2)]
  for h in range(1,H+2):
    for w in range(1,W+2):
      if S[h][w]=='.':
        total[h][w] = L[h][w]+R[h][w]+U[h][w]+D[h][w]+1
        ans = max(ans,total[h][w])
  return ans
print(solve())

Submission status: Time Limit Exceeded

Solution code:
H, W, *SS = open(0).read().split()
H, W = int(H), int(W)

R = [[0]*(W) for _ in [0]*(H)]
C = [[0]*(W) for _ in [0]*(H)]

for i, S in enumerate(SS):
    cnt = 0
    pre = S[0]
    for j, s in enumerate(S):
        if s == '.':
            cnt += 1
        else:
            if pre == '.':
                for k in range(1, cnt+1):
                    R[i][j-k] = cnt
                cnt = 0
        pre = s
    if pre == '.':
        for k in range(1, cnt+1):
            R[i][-k] = cnt

for j in range(W):
    cnt = 0
    pre = SS[0][j]
    for i in range(H):
        s = SS[i][j]
        if s == '.':
            cnt += 1
        else:
            if pre == '.':
                for k in range(1, cnt+1):
                    C[i-k][j] = cnt
                cnt = 0
        pre = s
    if pre == '.':
        for k in range(1, cnt+1):
            C[-k][j] = cnt

ans = 0
for i in range(H):
    for j in range(W):
        if R[i][j] and C[i][j]:
            area = R[i][j]+C[i][j]-1
            if ans < area:
                ans = area
print(ans)

Submission status: Time Limit Exceeded

Solution code:
MOD = 10**9+7
h, w = map(int, input().split())
S = [input() for _ in range(h)]
L = [[0]*w for _ in range(h)]
R = [[0]*w for _ in range(h)]
U = [[0]*w for _ in range(h)]
D = [[0]*w for _ in range(h)]
for i in range(h):
  for j in range(w):
    if j > 0:
      if S[i][j-1] == ".":
        L[i][j] = L[i][j-1]+1
      if S[i][w-j] == ".":
        R[i][w-1-j] = R[i][w-j]+1
    if i > 0:
      if S[i-1][j] == ".":
        U[i][j] = U[i-1][j]+1
      if S[h-i][j] == ".":
        D[h-1-i][j] = D[h-i][j]+1
ans = 0
for i in range(h):
  for j in range(w):
    if S[i][j] == ".":
      temp = L[i][j]+R[i][j]+U[i][j]+D[i][j]+1
      ans = max(ans, temp)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

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

S = [input() + '#' for _ in range(H)]
S.append('#' * (W + 1))

rows = np.zeros(shape=(H, W), dtype=np.int64)
cols = np.zeros(shape=(W, H), dtype=np.int64)

for y in range(H):
    cont = 0
    for x in range(W + 1):
        if S[y][x] == '.':
            cont += 1
        else:
            rows[y][x - cont:x] = cont
            cont = 0

for x in range(W):
    cont = 0
    for y in range(H + 1):
        if S[y][x] == '.':
            cont += 1
        else:
            cols[x][y - cont:y] = cont
            cont = 0

print(np.max(rows + cols.T) - 1)

Submission status: Time Limit Exceeded

Solution code:
H, W = map(int, input().split(' '))

S = [input() for _ in range(H)]

rows = []
cols = []

for y in range(H):
    cont = 0
    row = []
    for x in range(W):
        if S[y][x] == '.':
            cont += 1
        else:
            for _ in range(cont):
                row.append(cont)
            row.append(0)
            cont = 0
    for _ in range(cont):
        row.append(cont)
    rows.append(row)

for x in range(W):
    cont = 0
    col = []
    for y in range(H):
        if S[y][x] == '.':
            cont += 1
        else:
            for _ in range(cont):
                col.append(cont)
            col.append(0)
            cont = 0
    for _ in range(cont):
        col.append(cont)
    cols.append(col)

ans = 0
for y in range(H):
    for x in range(W):
        if S[y][x] == '.':
            ans = max(ans, rows[y][x] + cols[x][y] - 1)

print(ans)

Submission status: Time Limit Exceeded

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

ans = 0
L = [[0]*w for _ in range(h)]
for hi in range(h):
    cnt = 1
    for wi in range(w):
        if S[hi][wi]=='#':
            L[hi][wi] = 0
            cnt = 1
        else:
            L[hi][wi] = cnt
            cnt += 1

R = [[0]*w for _ in range(h)]
for hi in range(h):
    cnt = 1
    for wi in range(w):
        if S[hi][w-wi-1]=='#':
            R[hi][w-wi-1] = 0
            cnt = 1
        else:
            R[hi][w-wi-1] = cnt
            cnt += 1

D = [[0]*w for _ in range(h)]
for wi in range(w):
    cnt = 1
    for hi in range(h):
        if S[hi][wi]=='#':
            D[hi][wi] = 0
            cnt = 1
        else:
            D[hi][wi] = cnt
            cnt += 1

U = [[0]*w for _ in range(h)]
for wi in range(w):
    cnt = 1
    for hi in range(h):
        if S[h-hi-1][wi] == '#':
            U[h-hi-1][wi] = 0
            cnt = 1
        else:
            U[h-hi-1][wi] = cnt
            cnt += 1

ans = 0
for hi in range(h):
    for wi in range(w):
        ans = max(ans, L[hi][wi]+R[hi][wi]+D[hi][wi]+U[hi][wi]-3)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
def main():
    h,w = map(int,input().split())
    s = []
    for i in range(h):
        s.append(input())
    dp = [[0 for i in range(w)] for i in range(h)]
    for i in range(h):
        p = [-1]
        for j in range(w):
            if s[i][j] == '#':
                p.append(j)
        p.append(w)
        for k in range(len(p)-1):
            for j in range(p[k]+1,p[k+1]):
                dp[i][j] = p[k+1]-p[k]-1
    for j in range(w):
        p = [-1]
        for i in range(h):
            if s[i][j] == '#':
                p.append(i)
        p.append(h)
        for k in range(len(p)-1):
            for i in range(p[k]+1,p[k+1]):
                dp[i][j] += p[k+1]-p[k]-1
    ans = 0
    for i in range(h):
        for j in range(w):
            if dp[i][j] > ans:
                ans = dp[i][j]
    print(ans-1)


if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
H, W = map(int, input().split())

G = []
for _ in range(H):
    G.append(list(input()))

L, R, U, B = [], [], [], []
for y in range(H):
    targets = [L, R]
    ranges = [range(W), range(W-1, -1, -1)]
    for target, rng in zip(targets, ranges):
        row = [0] * W
        c = -1
        for x in rng:
            if G[y][x] == "#":
                c = -1
            else:
                c += 1
            row[x] = c
        target.append(row)
for x in range(W):
    targets = [U, B]
    ranges = [range(H), range(H-1, -1, -1)]
    for target, rng in zip(targets, ranges):
        col = [0] * H
        c = -1
        for y in rng:
            if G[y][x] == "#":
                c = -1
            else:
                c += 1
            col[y] = c
        target.append(col)

max_light = 0
for y in range(H):
    row = [0] * W
    for x in range(W):
        light = L[y][x] + R[y][x] + U[x][y] + B[x][y] + 1
        max_light = max(light, max_light)
print(max_light)

Submission status: Time Limit Exceeded

Solution code:
def readinput():
    h,w=map(int,input().split())
    smat=[]
    for _ in range(h):
        smat.append(input())
    return h,w,smat

def main(h,w,smat):
    tmat=[]
    for _ in range(h):
        t=[0 for tt in range(w)]
        tmat.append(t)
    #print(tmat)
    for i in range(h):
        s=smat[i]
        l=0
        r=s.find('#',l)
        #print(i,l,r)
        while(r>=0):
            for k in range(l,r):
                tmat[i][k]=r-l
            l=r+1
            if (l>=w):
                break
            r=s.find('#',l)
            #print(i,l,r)
        else:
            for k in range(l,w):
                tmat[i][k]=w-l
        #print(tmat[i])
    maxt=0
    for j in range(w):
        u=0
        b=u
        while b<h:
            #print(b,j)
            while b<h and smat[b][j]=='.':
                b+=1
            for k in range(u,b):
                maxt=max(maxt, tmat[k][j]+b-u-1)
            u=b+1
            b=u

    return maxt

def main2(h,w,smat):
    l=[]
    r=[]
    u=[]
    d=[]
    for _ in range(h):
        l.append([0]*w)
        r.append([0]*w)
        u.append([0]*w)
        d.append([0]*w)

    for i in range(h):
        for j in range(w):
            if smat[i][j]=='.':
                if j==0:
                    l[i][j]=1
                else:
                    l[i][j]=l[i][j-1]+1
        for j in range(w-1,-1,-1):
            if smat[i][j]=='.':
                if j==w-1:
                    r[i][j]=1
                else:
                    r[i][j]=r[i][j+1]+1
    for j in range(w):
        for i in range(h):
            if smat[i][j]=='.':
                if i==0:
                    u[i][j]=1
                else:
                    u[i][j]=u[i-1][j]+1
        for i in range(h-1,-1,-1):
            if smat[i][j]=='.':
                if i==h-1:
                    d[i][j]=1
                else:
                    d[i][j]=d[i+1][j]+1
    
    maxt=0
    for i in range(h):
        for j in range(w):
            maxt=max(maxt, l[i][j]+r[i][j]+u[i][j]+d[i][j]-3)
    return maxt

if __name__=='__main__':
    h,w,smat=readinput()
    ans=main2(h,w,smat)
    print(ans)

Submission status: Time Limit Exceeded

Solution code:
def readinput():
    h,w=map(int,input().split())
    smat=[]
    for _ in range(h):
        smat.append(input())
    return h,w,smat

def main(h,w,smat):
    tmat=[]
    for _ in range(h):
        t=[0 for tt in range(w)]
        tmat.append(t)
    #print(tmat)
    for i in range(h):
        s=smat[i]
        l=0
        r=s.find('#',l)
        #print(i,l,r)
        while(r>=0):
            for k in range(l,r):
                tmat[i][k]=r-l
            l=r+1
            if (l>=w):
                break
            r=s.find('#',l)
            #print(i,l,r)
        else:
            for k in range(l,w):
                tmat[i][k]=w-l
        #print(tmat[i])
    maxt=0
    for j in range(w):
        u=0
        b=u
        while b<h:
            #print(b,j)
            while b<h and smat[b][j]=='.':
                b+=1
            for k in range(u,b):
                maxt=max(maxt, tmat[k][j]+b-u-1)
            u=b+1
            b=u

    return maxt

if __name__=='__main__':
    h,w,smat=readinput()
    ans=main(h,w,smat)
    print(ans)

Submission status: Time Limit Exceeded

Solution code:
H,W = map(int,input().split())

s = []
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):
    tmp =list(input())
    s.append(tmp)

for y in range(H):
  for x in range(W):
    if s[y][x] == "#":
      continue
    elif x == 0:
      l[y][x] = 1
    else:
      l[y][x] = l[y][x-1] + 1

for y in range(H):
  for x in range(W-1, -1, -1):
    if s[y][x] == "#":
      continue
    elif x == W - 1:
      r[y][x] = 1
    else:
      r[y][x] = r[y][x+1] + 1
      
for y in range(H):
  for x in range(W):
    if s[y][x] == "#":
      continue
    elif y == 0:
      u[y][x] = 1
    else:
      u[y][x] = u[y-1][x] + 1
      
for y in range(H-1, -1, -1):
  for x in range(W):
    if s[y][x] == "#":
      continue
    elif y == H - 1:
      d[y][x] = 1
    else:
      d[y][x] = d[y+1][x] + 1

ans = 0
for x in range(H):
  for y in range(W):
    if ans < l[x][y] + r[x][y] + u[x][y] + d[x][y] - 3:
      ans = l[x][y] + r[x][y] + u[x][y] + d[x][y] - 3
      
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import copy

H, W = map(int, input().split())
grid = [[1 if c == "." else 0 for c in input()] for _ in range(H)]

L = copy.deepcopy(grid)
R = copy.deepcopy(grid)
U = copy.deepcopy(grid)
D = copy.deepcopy(grid)

for i in range(H):
  for j in range(1, W):
    L[i][j] = (L[i][j-1] + 1) * L[i][j]
    R[i][-1-j] = (R[i][-j] + 1) * R[i][-1-j]

for j in range(W):
  for i in range(1, H):
    U[i][j] = (U[i-1][j] + 1) * U[i][j]
    D[-1-i][j] = (D[-i][j] + 1) * D[-1-i][j]

ans = 0

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

print(ans)

Submission status: Time Limit Exceeded

Solution code:
H, W = map(int, input().split())
H += 2
W += 2
grid = '#' * W
for _ in range(H-2):
    grid += '#' + input() + '#'
grid += '#' * W

HL = [[0]*W for _ in range(H)]
WL = [[0]*H for _ in range(W)]

for i in range(H):
  left = 0
  right = 0
  for j in range(W):
    if grid[W*i+j] == "#":
      left = 0
    else:
      left += 1
      HL[i][j] += left
    if grid[W*(i+1)-1-j] == "#":
      right = 0
    else:
      right += 1
      HL[i][-1-j] += right - 1

for j in range(W):
  left = 0
  right = 0
  for i in range(H):
    if grid[j+i*W] == "#":
      left = 0
    else:
      left += 1
      WL[j][i] += left
    if grid[j+(H-1-i)*W] == "#":
      right = 0
    else:
      right += 1
      WL[j][-1-i] += right - 1

ans = 0

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

print(ans)

Submission status: Time Limit Exceeded

Solution code:
H, W = map(int, input().split())
H += 2
W += 2
grid = '#' * W
for _ in range(H-2):
    grid += '#' + input() + '#'
grid += '#' * W

HL = [[0]*W for _ in range(H)]
WL = [[0]*H for _ in range(W)]

for i in range(H):
  temp = grid[W*i:W*(i+1)]
  left = 0
  right = 0
  for j in range(W):
    if temp[j] == "#":
      left = 0
    else:
      left += 1
      HL[i][j] += left
    if temp[-1-j] == "#":
      right = 0
    else:
      right += 1
      HL[i][-1-j] += right - 1

for j in range(W):
  temp = grid[j::W]
  left = 0
  right = 0
  for i in range(H):
    if temp[i] == "#":
      left = 0
    else:
      left += 1
      WL[j][i] += left
    if temp[-1-i] == "#":
      right = 0
    else:
      right += 1
      WL[j][-1-i] += right - 1

ans = 0

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

print(ans)

Submission status: Time Limit Exceeded

Solution code:
H, W = map(int, input().split())
H += 2
W += 2
grid = '#' * W
for _ in range(H-2):
    grid += '#' + input() + '#'
grid += '#' * W

def dfs(start):
    move_list = [-1, 1, W, -W]
    L = 1
    for move in move_list:
      v = start
      cnt = 0
      while grid[v] == ".":
        v += move
        if grid[v] != "#":
          cnt += 1
      L += cnt
    return L

ans = max(dfs(v) for v in range(H*W) if grid[v] != "#")
print(ans)

Submission status: Time Limit Exceeded

Solution code:
H,W = map(int,input().split())

S = [[] for _ in range(H)]
for i in range(H):
    S[i] = list(input())

HL = [[] for _ in range(H)]
WL = [[] for _ in range(W)]
for i in range(H):
    for j in range(W):
        if S[i][j] == '#':
            HL[i].append(j)

for j in range(W):
    for i in range(H):
        if S[i][j] == '#':
            WL[j].append(i)
ma = 0
import bisect
for i in range(H):
    for j in range(W):
        if S[i][j] == '.':
            ind = bisect.bisect_left(HL[i],j)
            if ind == 0:
                left = -1
            else:
                left = HL[i][ind-1]
            if ind == len(HL[i]):
                right = W
            else:
                right = HL[i][ind]
            wid_num = right-left-1

            ind_2 = bisect.bisect_left(WL[j],i)
            if ind_2 == 0:
                up = -1
            else:
                up = WL[j][ind_2-1]
            if ind_2 == len(WL[j]):
                down = H
            else:
                down = WL[j][ind_2]
            len_num = down-up-1

            ma = max(ma,wid_num+len_num-1)
print(ma)

Submission status: Time Limit Exceeded

Solution code:
import sys


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


def main():
    h, w = map(int, read().split())
    s = [[False] * w] + [[False] + [i == "." for i in read()] + [False] for _ in range(h)] + [[False] * w]
    left = [[0] * (w + 2) for _ in range(h + 2)]
    right = [[0] * (w + 2) for _ in range(h + 2)]
    up = [[0] * (w + 2) for _ in range(h + 2)]
    down = [[0] * (w + 2) for _ in range(h + 2)]
    for y in range(1, h + 1):
        for x in range(1, w + 1):
            if s[y][x]:
                left[y][x] = left[y][x - 1] + 1
                up[y][x] = up[y - 1][x] + 1
            if s[-y - 1][-x - 1]:
                right[-y - 1][-x - 1] = right[-y - 1][-x] + 1
                down[-y - 1][-x - 1] = down[-y][-x - 1] + 1
    c = 0
    for y in range(1, h + 1):
        for x in range(1, w + 1):
            if s[y][x]:
                c = max(left[y][x] + right[y][x] + up[y][x] + down[y][x], c)
    print(c - 3)


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
import sys


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


def main():
    h, w = map(int, read().split())
    s = ["#" * w] + ["w" + read() + "w" for _ in range(h)] + ["w" * w]
    left = [[0] * (w + 2) for _ in range(h + 2)]
    right = [[0] * (w + 2) for _ in range(h + 2)]
    up = [[0] * (w + 2) for _ in range(h + 2)]
    down = [[0] * (w + 2) for _ in range(h + 2)]
    for y in range(1, h + 1):
        for x in range(1, w + 1):
            if s[y][x] == ".":
                left[y][x] = left[y][x - 1] + 1
                up[y][x] = up[y - 1][x] + 1
            if s[-y - 1][-x - 1] == ".":
                right[-y - 1][-x - 1] = right[-y - 1][-x] + 1
                down[-y - 1][-x - 1] = down[-y][-x - 1] + 1
    c = 0
    for y in range(1, h + 1):
        for x in range(1, w + 1):
            if s[y][x] == ".":
                c = max(left[y][x] + right[y][x] + up[y][x] + down[y][x], c)
    print(c - 3)


if __name__ == '__main__':
    main()