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())
grid = [input() for _ in range(H)]
ans = 0
vert = [[0] * W for _ in range(H)]; hori = [[0] * W for _ in range(H)];
for i in range(H):
    for j in range(W):
        if grid[i][j] == '.':
            hori[i][j] = hori[i][j-1] + 1 if j > 0 else 1
    for j in range(W-2, -1, -1):
        if grid[i][j] == '.' and grid[i][j+1] == '.':
            hori[i][j] = hori[i][j+1] 
for j in range(W):
    for i in range(H):
        if grid[i][j] == '.':
            vert[i][j] = vert[i-1][j] + 1 if i > 0 else 1
    for i in range(H-2, -1, -1):
        if grid[i][j] == '.' and grid[i+1][j] == '.':
            vert[i][j] = vert[i+1][j]
for i in range(H):
    for j in range(W):
        if grid[i][j] == '.':
            ans = max(ans, hori[i][j] + vert[i][j] - 1)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import sys,collections as cl,bisect as bs,copy
sys.setrecursionlimit(100000)
Max = sys.maxsize
def l():
	return list(map(int,input().split()))
def m():
	return map(int,input().split())
def s(x):
	a = []
	aa = x[0]
	su = 1
	for i in range(len(x)-1):
		if aa == x[i+1]:
			a.append([aa,su])
			aa = x[i+1]
			su = 1
		else:
			su += 1
	a.append([aa,su])
	return a
def jo(x):
	return " ".join(map(str,x))

h,w = m()

k = [[0 for j in range(w)] for i in range(h)]
for i in range(h):
	l = list(input())
	for j in range(w):
		if l[j] != "#":
			k[i][j] = 1

kk = copy.deepcopy(k)
ma = 0
for i in range(h):
	for j in range(1,w):
		if k[i][j] != 0:
			k[i][j] += k[i][j-1]
	for j in range(w-2,-1,-1):
		if k[i][j] != 0 and k[i][j+1]  != 0:
			k[i][j] = k[i][j+1]

for i in range(w):
	for j in range(1,h):
		if kk[j][i] != 0:
			kk[j][i] += kk[j-1][i]
	for j in range(h-2,-1,-1):
		if kk[j][i] != 0 and kk[j+1][i] != 0:
			kk[j][i] = kk[j+1][i]

for i in range(h):
	for j in range(w):
		if ma <= kk[i][j] + k[i][j] - 1:
			ma = kk[i][j] + k[i][j] - 1
print(ma)

Submission status: Time Limit Exceeded

Solution code:
import sys
from collections import deque
import copy
import math
def get_read_func(fileobject):
    if fileobject == None :
        return  sys.stdin.readline
    else:
        return fileobject.readline

def calc(field, H, W):
    ret =  [[0] * (W + 1) for i in range(H + 1)]
    for i in range(H):
        cnt = 0
        cnt_list = []
        for j in range(W + 1):
            if field[i][j] == "#":
                cnt_list.append(cnt)
                cnt = 0
            else:
                cnt += 1
        k = 0
        for j in range(W + 1):
            if field[i][j] == ".":
                ret[i][j] = cnt_list[k]
            else:
                ret[i][j] = 0
                k+=1
    return ret





def main():
    if len(sys.argv) > 1:
        f = open(sys.argv[1])
    else:
        f = None
    read_func = get_read_func(f);
    input_raw = read_func().strip().split()
    [H, W] = [int(input_raw[0]), int(input_raw[1])]
    field = [["#"] * (W + 1) for i in range(H + 1)]
    field_T = [["#"] * (H + 1) for i in range(W + 1)]
    for i in range(H):
        input_raw = read_func().strip().split()
        for j in range(W):
            field[i][j] = input_raw[0][j]
            field_T[j][i] = field[i][j]
    ret1 = calc(field, H, W)
    ret2 = calc(field_T, W, H)
    ans = 0
    for i in range(H):
        for j in range(W):
            ans = max(ans, ret1[i][j] + ret2[j][i] - 1)
    print ans

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
h, w = map(int, input().split())
m = [input().strip() 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 y in range(h):
    for x in range(w):
        dy = y
        uy = h - y - 1
        if m[dy][x] == '.':
            if dy == 0:
                d[dy][x] = 1
            else:
                d[dy][x] = d[dy - 1][x] + 1
        if m[uy][x] == '.':
            if uy == (h - 1):
                u[uy][x] = 1
            else:
                u[uy][x] = u[uy + 1][x] + 1

        lx = x
        rx = w - x - 1
        if m[y][lx] == '.':
            if lx == 0:
                l[y][lx] = 1
            else:
                l[y][lx] = l[y][lx - 1] + 1
        if m[y][rx] == '.':
            if rx == (w - 1):
                r[y][rx] = 1
            else:
                r[y][rx] = r[y][rx + 1] + 1

ans = 0
for y in range(h):
    for x in range(w):
        t = l[y][x] + r[y][x] + u[y][x] + d[y][x] - 3
        if t > ans:
            ans = t
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
words = lambda t : list(map(t, input().split()))

h,w = words(int)
wq = [0] * w

grid = []
grid.append(['#'] * (w+2))
for i in range(h):
    grid.append(np.array(['#'] + list(input()) + ['#']))
grid.append(['#'] * (w+2))
np.array(grid)

l = np.zeros((h+2,w+2))
r = np.zeros((h+2,w+2))
u = np.zeros((h+2,w+2))
d = np.zeros((h+2,w+2))

#for i in range(h+2):
#    print(grid[i])


for i in range(1,h+1):
    for j in range(1,w+1):
        if not grid[i][j] == '#':
            l[i][j] = l[i][j-1]+1
            u[i][j] = u[i-1][j]+1

for i in range(h+1,0,-1):
    for j in range(w+1,0,-1):
        if not grid[i][j] == '#':
            r[i][j] = r[i][j+1]+1
            d[i][j] = d[i+1][j]+1


print(int((l+r+u+d).max()-3))

Submission status: Time Limit Exceeded

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

r = [[[0, 0] for _ in range(w)] for _ in range(h)]

for i in range(h):
  count = 0
  p = -1
  for j in range(w):
    if s[i][j] == '.':
      count += 1
      if p == -1:
        p = j
    else:
      if not p == -1:
        for k in range(p, j):
          r[i][k][0] = count
        p = -1
        count = 0
  if not p == -1:
    for k in range(p, j+1):
      r[i][k][0] = count

for j in range(w):
  count = 0
  p = -1
  for i in range(h):
    if s[i][j] == '.':
      count += 1
      if p == -1:
        p = i
    else:
      if not p == -1:
        for k in range(p, i):
          r[k][j][1] = count
        p = -1
        count = 0
  if not p == -1:
    for k in range(p, i+1):
      r[k][j][1] = count

ans = 0

for row in r:
  # print(row)
  for e in row:
    t = e[0] + e[1]
    if ans < t:
      ans = t

print(ans-1)

Submission status: Time Limit Exceeded

Solution code:
from sys import stdin
import numpy as np

H, W = [int(x) for x in stdin.readline().rstrip().split()]
S = [stdin.readline().rstrip() for _ in range(H)]
S_new = np.array([[1 if S[k][l] == '#' else 0 for l in range(W)] for k in range(H)])
up = np.zeros((H, W))
down = np.zeros((H, W))
left = np.zeros((H, W))
right = np.zeros((H, W))

for y in range(H):
    cnt = 0
    for x in range(W - 1):
        if S_new[y][x] == 0:
            cnt += 1
        else:
            cnt = 0
        left[y][x + 1] = cnt
    cnt = 0
    for x in range(W - 1):
        if S_new[y][W - x - 1] == 0:
            cnt += 1
        else:
            cnt = 0
        right[y][W - x - 2] = cnt

for x in range(W):
    cnt = 0
    for y in range(H - 1):
        if S_new[:, x][y] == 0:
            cnt += 1
        else:
            cnt = 0
        up[y + 1][x] = cnt
    cnt = 0
    for y in range(H - 1):
        if S_new[:, x][H - y - 1] == 0:
            cnt += 1
        else:
            cnt = 0
        down[H - y - 2][x] = cnt

sums = np.array([[up[y][x] + down[y][x] + left[y][x] + right[y][x] + 1 if S_new[y][x] == 0 else 0 for x in range(W)] for y in range(H)])
print(int(sums.max()))

Submission status: Time Limit Exceeded

Solution code:
import copy
H, W = map(int, input().split())
MAP = [list('#' + input() + '#') for j in range(H)]
MAP.insert(0, ['#' for i in range(W + 2)])
MAP.append(['#' for i in range(W + 2)])
MAP2 = copy.deepcopy(MAP)


def line(MAP):
    for i in range(1, H + 2):
        before = 0
        for j in range(1, W + 2):
            if MAP[i][j] == '#':
                for x in range(before + 1, j):
                    MAP[i][x] = j - before - 1
                before = j


def column(MAP2):
    for j in range(1, W + 2):
        before = 0
        for i in range(1, H + 2):
            if MAP2[i][j] == '#':
                for y in range(before + 1, i):
                    global ans
                    ans = max(ans, i - before - 1 + MAP[y][j])
                before = i


line(MAP)
ans = 0
column(MAP2)
print(ans - 1)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
def solve():
    h, w = map(int, input().split())
    S = list(input() + '#' for _ in range(h)) + ['#' * (w + 1)]
    H = np.zeros([h + 1, w], dtype=np.int)
    W = np.zeros([h + 1, w], dtype=np.int)
    for r in range(h):
        c = 0
        while c < w:
            if S[r][c] == '.':
                t = S[r][c:].find('#')
                for j in range(c, c + t):
                    W[r][j] = t
                c += t
            c += 1
    for c in range(w):
        r = 0
        while r < h:
            if S[r][c] == '.':
                t = r + 1
                cnt = 1
                while S[t][c] == '.':
                    t += 1
                    cnt += 1
                for i in range(r, t):
                    H[i][c] = cnt
                r = t
            r += 1
    ans = 0
    for r in range(h):
        for c in range(w):
            ans = max(ans, H[r][c] + W[r][c] - 1)
    print(ans)
solve()

Submission status: Time Limit Exceeded

Solution code:
import sys

h, w = map(int, raw_input().split(" "))

glid = []

for i in range(0, h):
    s = raw_input()
    glid.append(s)

cost = [[-1 for y in range(0, h)] for x in range(0, w)]
for x in range(0, w):
    start = 0
    count = 0
    for y in range(0, h + 1):
        if y < h and glid[y][x] != "#":
            count += 1
        else:
            for i in range(start, y):
                cost[x][i] = count
            count = 0
            start = y + 1

# for y in range(0, h):
#     for x in range(0, w):
#         sys.stdout.write(str(cost[x][y]) + "\t")
#     print

ans = 0
for y in range(0, h):
    start = 0
    count = 0
    for x in range(0, w + 1):
        if x < w and glid[y][x] != "#":
            count += 1
        else:
            for i in range(start, x):
                cost[i][y] += (count - 1)
                ans = max(ans, cost[i][y])
            count = 0
            start = x + 1

print(ans)

Submission status: Time Limit Exceeded

Solution code:
def hor_set_values(harr, i, left, right):
    # print("Hor:", harr, i, left, right)

    value = right - left - 1
    for j in range(left + 1, right):
        harr[i-1][j-1] = value

    # print("Hor:", harr)


def make_horizontal(marr, h, w):
    harr = []

    for i in range(1, h + 1):
        harr.append([0] * w)

        left = 0
        right = 0

        # set values
        for j in range(1, w + 1):

            right += 1
            if marr[i-1][j-1]:
                hor_set_values(harr, i, left, right)
                left = right

            elif j == w:
                hor_set_values(harr, i, left, right + 1)

    # print(harr)
    return harr


def tranpose(marr):
    return [list(i) for i in zip(*marr)]


def solve():
    h, w = [int(x) for x in input().split()]
    marr = []

    for i in range(h):
        line = str(input())
        marr.append([])

        for j in range(w):
            marr[i].append(0)
            if line[j] == '#':
                marr[i][j] = 1
    # print(marr)
    t_marr = tranpose(marr)
    # print(t_marr)

    harr = make_horizontal(marr, h, w)
    # print(harr)
    varr = tranpose(make_horizontal(t_marr, w, h))
    # print(varr)

    ans = 0
    for i in range(h):
        for j in range(w):
            ans = max(ans, harr[i][j] + varr[i][j])

    print(ans - 1)


if __name__ == '__main__':
    solve()

Submission status: Time Limit Exceeded

Solution code:

H,W = input().split()
H = int(H)
W = int(W)
S = []

for i in range(H):

    sp = input()
    S.append(sp)

maxi = 0
now = 0

for i in range(H):

    for j in range(W):

        if ( S[i][j] != "#"):

            now = 1

            for k in range(j):
                k = j - 1 - k

                if (S[i][k] == "."):
                    now += 1

                else:
                    break

            for k in range(W - 1 - j):
                k = j + 1 + k

                if (S[i][k] == "."):
                    now += 1

                else:
                    break

            for k in range(i):
                k = i - 1 - k

                if (S[k][j] == "."):
                    now += 1

                else:
                    break

            for k in range(H - 1 - i):
                k = i + k + 1

                if (S[k][j] == "."):
                    now += 1

                else:
                    break


            if (maxi < now):
                maxi = now
            

print (maxi)

Submission status: Time Limit Exceeded

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

mm = ['#' + input() + '#' for i in range(h)]
m = ['#' * (w+2)] + mm + ['#' * (w+2)]

# for i in range(h+2):
#     print(m[i])

#vertical = [[0] * (w+1) for i in range(h+1)]
vertical = [[0], ]
for i in range(1, h+1):
    c = 0
    tmp = [0]
    for j in range(1, w+2):
        if m[i][j] == '#':
            tmp.extend([j-c-1] * (j-c-1))
            tmp.append(0)
            c = j
    vertical.append(tmp)

# for i in range(1, h+1):
#     print(vertical[i])

#horizontal = [[0] * (w+1) for i in range(h+1)]
horizontal = [[0], ]
for i in range(1, w+1):
    c = 0
    tmp = [0]
    for j in range(1, h+2):
        if m[j][i] == '#':
            tmp.extend([j-c-1] * (j-c-1))
            tmp.append(0)
            c = j
    horizontal.append(tmp)

# for i in range(1, w+1):
#     print(horizontal[i])

ans = 1
for i in range(1, h+1):
    for j in range(1, w+1):
        ans = max(ans, vertical[i][j] + horizontal[j][i] - 1)

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, log2
from itertools import permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from numpy.fft import fft, ifft
from fractions import gcd
import numpy as np

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

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

L = [[0]*W for _ in range(H)]
R = [[0]*W for _ in range(H)]
D = [[0]*W for _ in range(H)]
U = [[0]*W for _ in range(H)]


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

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

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

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

L = np.array(L)
R = np.array(R)
U = np.array(U)
D = np.array(D)

print((L+R+U+D).max()-3)

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
from sys import stdin
import numpy as np
from itertools import accumulate
# import sys
# sys.setrecursionlimit(10**4)

def _li(): return list(map(int, stdin.readline().split()))
def _li_(): return list(map(lambda x: int(x)-1, stdin.readline().split()))
def _lf(): return list(map(float, stdin.readline().split()))
def _ls(): return stdin.readline().split()
def _i(): return int(stdin.readline())
def _f(): return float(stdin.readline())
def _s(): return stdin.readline()[:-1]


H, W = _li()
S = []
mapping = {'#': 0, '.': 1}
for _ in range(H):
    S.append(list(map(lambda x: mapping[x], list(_s()))))

S = np.array(S)
tS = S.T
h1_cum, h2_cum = [], []
for i in range(H):
    h1_cum.append(list(accumulate(S[i, :], lambda x, y: (x+y)*y)))
    h2_cum.append(list(accumulate(S[i, ::-1], lambda x, y: (x+y)*y)))

v1_cum, v2_cum = [], []
for i in range(W):
    v1_cum.append(list(accumulate(tS[i, :], lambda x, y: (x+y)*y)))
    v2_cum.append(list(accumulate(tS[i, ::-1], lambda x, y: (x+y)*y)))

ans = 0
for i in range(H):
    for j in range(W):
        if S[i, j] == 1:
            ans = max(ans,
                      h1_cum[i][j] + h2_cum[i][-1-j]
                      + v1_cum[j][i] + v2_cum[j][-1-i] - 3)

print(ans)

Submission status: Time Limit Exceeded

Solution code:
h,w=map(int,input().split())
sl=[input() for i in range(h)]
ll=[[0]*w for i in range(h)]
for i in range(h):
    for j in range(w):
        if sl[i][j]=='.':
            if j==0:
                ll[i][j]=1
            else:
                ll[i][j]=ll[i][j-1]+1
        else:
            ll[i][j]=0
rl=[[0]*w for i in range(h)]
for i in range(h):
    for j in range(w-1,-1,-1):
        if sl[i][j]=='.':
            if j==w-1:
                rl[i][j]=1
            else:
                rl[i][j]=rl[i][j+1]+1
        else:
            rl[i][j]=0
ul=[[0]*w for i in range(h)]
for j in range(w):
    for i in range(h):
        if sl[i][j]=='.':
            if i==0:
                ul[i][j]=1
            else:
                ul[i][j]=ul[i-1][j]+1
        else:
            ul[i][j]=0
dl=[[0]*w for i in range(h)]
for j in range(w):
    for i in range(h-1,-1,-1):
        if sl[i][j]=='.':
            if i==h-1:
                dl[i][j]=1
            else:
                dl[i][j]=dl[i+1][j]+1
        else:
            dl[i][j]=0
ans=0
for i in range(h):
    for j in range(w):
            ans=max(ans,ll[i][j]+rl[i][j]+ul[i][j]+dl[i][j]-3)
print(ans)

Submission status: Time Limit Exceeded

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

H, W = (int(i) for i in input().split())
#e = [[i for i in input().split()] for i in range(H)]
e = []
for x in range(H):
    e.append(list(input()))

maxcount = 1
for i in range(H):
    for j in range(W):
        #print("start", i, j)
        count = 1
        if e[i][j] == "#":
            continue
        for k in range(i+1, H):
            #print(e[k][j], k, j)
            if e[k][j] == "#":
                #print(k, j)
                break
            else:
                count +=1
        #print("1 ", count)
        for l in range(1, i+1):
            #print(e[i-l][j], i-l, j)
            if e[i-l][j] == "#":
                break
            else:
                count += 1
        #print("2 ", count)
        if count + W -1 < maxcount:
            continue
        for m in range(j+1, W):
            if e[i][m] == "#":
                break
            else:
                count +=1
        #print("3 ",count)
        for n in range(1, j+1):
            if e[i][j-n] == "#":
                break
            else:
                count +=1
        if maxcount < count:
            maxcount = count
        if maxcount == W+H:
            break
    else:
        continue
    break
print(maxcount)

Submission status: Time Limit Exceeded

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


ans=0
for i in range(h):
  for j in range(w):
    if s[i][j]==".":
      rmasu=0
      for r in range(1,w-j):
        if s[i][j+r]==".":
          rmasu+=1
        else:
          break
      lmasu=0
      for l in range(1,j+1):
        if s[i][j-l]==".":
          lmasu+=1
        else:
          break
      umasu=0
      for u in range(1,i+1):
        if s[i-u][j]==".":
          umasu+=1
        else:
          break
      dmasu=0
      for d in range(1,h-i):
        
        if s[i+d][j]==".":
          dmasu+=1
        else:
          break
      allmasu=1+rmasu+lmasu+umasu+dmasu
      
      if ans<allmasu:
        ans=allmasu
      
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
words = lambda t : list(map(t, input().split()))

h,w = words(int)
wq = [0] * w

grid = []
grid.append(['#'] * (w+2))
for i in range(h):
    grid.append(['#'] + list(input()) + ['#'])
grid.append(['#'] * (w+2))

l = np.array([[0] * (w+2) for _ in range(h+2)])
r = np.array([[0] * (w+2) for _ in range(h+2)])
u = np.array([[0] * (w+2) for _ in range(h+2)])
d = np.array([[0] * (w+2) for _ in range(h+2)])

#for i in range(h+2):
#    print(grid[i])



for i in range(1,h+1):
    for j in range(1,w+1):
        if grid[i][j] == '#':
            continue
        else:
            l[i][j] = l[i][j-1]+1

for i in range(1,h+1):
    for j in range(w+1,0,-1):
        if grid[i][j] == '#':
            continue
        else:
            r[i][j] = r[i][j+1]+1

for j in range(1,w+1):
    for i in range(1,h+1):
        if grid[i][j] == '#':
            continue
        else:
            u[i][j] = u[i-1][j]+1

for j in range(1,w+1):
    for i in range(h+1,0,-1):
        if grid[i][j] == '#':
            continue
        else:
            d[i][j] = d[i+1][j]+1

print((l+r+u+d).max()-3)

Submission status: Time Limit Exceeded

Solution code:
import sys
sys.setrecursionlimit(10**7)
INF = 10 ** 18
MOD = 10 ** 9 + 7
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def SI(): return input()
import numpy

def main():
    H, W = LI()
    S = numpy.zeros((H, W), dtype=int)
    for i in range(H):
        for j, k in enumerate(SI()):
            if k == '#':
                S[i, j] = 1
    L = numpy.zeros((H, W), dtype=int)
    R = numpy.zeros((H, W), dtype=int)
    T = numpy.zeros((H, W), dtype=int)
    B = numpy.zeros((H, W), dtype=int)
    for i in range(H):
        l = 0
        r = 0
        for j in range(W):
            if S[i, j] == 1:
                l = 0
            else:
                l += 1
            L[i, j] = l
            if S[i, -1 - j] == 1:
                r = 0
            else:
                r += 1
            R[i, -1 - j] = r
    for j in range(W):
        t = 0
        b = 0
        for i in range(H):
            if S[i, j] == 1:
                t = 0
            else:
                t += 1
            T[i, j] = t
            if S[-1 - i, j] == 1:
                b = 0
            else:
                b += 1
            B[-1 - i, j] = b
    ans = numpy.max(L + R + T + B) - 3
    return ans

print(main())

Submission status: Time Limit Exceeded

Solution code:
import sys

h, w = map(int, raw_input().split(" "))

glid = []

for i in range(0, h):
    s = raw_input()
    glid.append(s)

count1 = [[-1 for y in range(0, h)] for x in range(0, w)]
for x in range(0, w):
    start = 0
    count = 0
    for y in range(0, h + 1):
        if y < h and glid[y][x] != "#":
            count += 1
        else:
            for i in range(start, y):
                count1[x][i] = count
            count = 0
            start = y + 1

# for y in range(0, h):
#     for x in range(0, w):
#         sys.stdout.write(str(count1[x][y]) + "\t")
#     print

count2 = [[-1 for y in range(0, h)] for x in range(0, w)]
for y in range(0, h):
    start = 0
    count = 0
    for x in range(0, w + 1):
        if x < w and glid[y][x] != "#":
            count += 1
        else:
            for i in range(start, x):
                count2[i][y] = count
            count = 0
            start = x + 1

# print
# for y in range(0, h):
#     for x in range(0, w):
#         sys.stdout.write(str(count2[x][y]) + "\t")
#     print

ans = 0
for x in range(0, w):
    for y in range(0, h):
        if glid[y][x] != "#":
            ans = max(ans, count1[x][y] + count2[x][y] - 1)

print(ans)

Submission status: Time Limit Exceeded

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

s = [[j for j in list(str(input()))] for i in range(h)]

board = [[[0 for _ in range(2)] for _ in range(w)] for _ in range(h)]

# 右、左、上、下の順に走査
for i in range(h):
    cnt_continue = 0
    for j in range(w):
        if s[i][j] == "#":
            cnt_continue = 0
        else:
            cnt_continue += 1
            board[i][j][0] = cnt_continue

for i in range(h):
    for j in reversed(range(w-1)):
        if board[i][j][0] == 0:
            continue
        board[i][j][0] = max(board[i][j][0], board[i][j+1][0])

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

for i in range(w):
    for j in reversed(range(h-1)):
        if board[j][i][1] == 0:
            continue
        board[j][i][1] = max(board[j][i][1], board[j+1][i][1])

ans = 0

for i in range(h):
    for j in range(w):
        v = sum(board[i][j]) - 1
        ans = max(ans, v)

print(ans)

Submission status: Time Limit Exceeded

Solution code:
H,W=map(int,input().split())
S=[input() for i in range(H)]
A=[[0]*W for i in range(H)]
B=[[0]*W for i in range(H)]
for i in range(H):
    s=0
    t=0
    num=0
    while t<W:
        #print(s,t,num)
        if S[i][t]=='#':
            for k in range(s,t):
                A[i][k]=num
            num=0
            t+=1
            s=t
        else:
            t+=1
            num+=1
    for k in range(s,t):
        A[i][k] = num
for j in range(W):
    s=0
    t=0
    num=0
    while t<H:
        #print(s,t,num)
        if S[t][j]=='#':
            for k in range(s,t):
                B[k][j]=num
            num=0
            t+=1
            s=t
        else:
            t += 1
            num += 1
    for k in range(s,t):
        B[k][j] = num
#print(A)
#print(B)
ans=0
for i in range(H):
    for j in range(W):
        if S[i][j]=='.':
            ans=max(ans,A[i][j]+B[i][j]-1)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
h,w = map(int, input().split())
smap = []
for _ in range(h):
  smap.append(input().strip())

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 y in range(h):
  for x in range(w):
    if smap[y][x] == '#':
      L[y][x] = 0
      D[y][x] = 0
    else:
      if 0 < x <= w-1:
        L[y][x] = L[y][x-1] + 1
      else:
        L[y][x] = 1
      if 0 < y <= h-1:
        D[y][x] = D[y-1][x] + 1
      else:
        D[y][x] = 1

for y in range(h-1, -1, -1):
  for x in range(w-1, -1, -1):
    if smap[y][x] == '#':
      R[y][x] = 0
      U[y][x] = 0
    else:
      if 0 <= x < w-1:
        R[y][x] = R[y][x+1] + 1
      else:
        R[y][x] = 1
      if 0 <= y < h-1:
        U[y][x] = U[y+1][x] + 1
      else:
        U[y][x] = 1

ans = 0
for y in range(h):
  for x in range(w):
    tmp = L[y][x] + R[y][x] + U[y][x] + D[y][x] - 3
    if ans < tmp:
      ans = tmp

print(ans)

Submission status: Time Limit Exceeded

Solution code:
H, W = map(int, input().split())
S = [input() for _ in range(H)]
X = [[[0] for _ in range(W)] for _ in range(H)]
Y = [[[0] for _ in range(W)] for _ in range(H)]
for i in range(H):
    x = [0]
    for j in range(W):
        if S[i][j] == '#':
            x = [0]
        else:
            x[0] += 1
            X[i][j] = x
for i in range(W):
    y = [0]
    for j in range(H):
        if S[j][i] == '#':
            y = [0]
        else:
            y[0] += 1
            Y[j][i] = y
ans = 0
for i in range(H):
    for j in range(W):
        ans = max(ans, X[i][j][0]+Y[i][j][0]-1)
print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
h,w=map(int,input().split())
s=[input() for i in range(h)]
ans=0
judge=0
c=0
for i in range(h):
    for j in range(w):
        if s[i][j]==".":
            for k in s[i][:j]:
                if k==".":c+=1
                else: c=0
            judge+=c
            c=0
            for k in s[i][j:]:
                if k == ".":
                    c += 1
                else: break
            judge += c
            c = 0
            for k in range(h-i):
                if s[k+i][j]==".":c+=1
                else: break
            judge+=c
            c=0
            for k in range(0,i):
                if s[k][j]==".":c+=1
                else: c=0
            judge+=c
            ans=max(ans,judge)
            judge=c=0
print(ans-1)