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 = list(map(int, input().split()))
S = [[1 if s=='.' else 0 for s in input()] for _ in range(H)] #S[h][w]

import numpy as np
S = np.array(S)
#print(S)

SH = np.zeros((H,W), dtype='int')
SH_ = np.zeros((H,W), dtype='int')

SV = np.zeros((H,W), dtype='int')
SV_ = np.zeros((H,W), dtype='int')

#horizontal
for h in range(H):
  SH[h][0] = S[h][0]
  for w in range(1,W):
    if S[h][w]:
      SH[h][w] = SH[h][w-1] + 1
  
  SH_[h][-1] = S[h][-1]
  for w in range(W-1)[::-1]:
    if S[h][w]:
      SH_[h][w] = SH_[h][w+1] + 1
  

#vertical
for w in range(W):
  SV[0][w] = S[0][w]
  for h in range(1,H):
    if S[h][w]:
      SV[h][w] = SV[h-1][w] + 1
  
  SV_[-1][w] = S[-1][w]
  for h in range(H-1)[::-1]:
    if S[h][w]:
      SV_[h][w] = SV_[h+1][w] + 1

#print(SH + SH_)
#print(SV + SV_)

print(np.max(SH+SH_+SV+SV_) -3)

Submission status: Time Limit Exceeded

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

us = [[0] * w for i in range(h)]
ds = [[0] * w for i in range(h)]
ls = [[0] * w for i in range(h)]
rs = [[0] * w for i in range(h)]

for x in range(w):
    u_cnt = 0
    for y in range(h):
        us[y][x] = u_cnt
        if cells[y][x] == '.':
            u_cnt += 1
        else:
            u_cnt = 0
    d_cnt = 0
    for y in range(h - 1, -1, -1):
        ds[y][x] = d_cnt
        if cells[y][x] == '.':
            d_cnt += 1
        else:
            d_cnt = 0
for y in range(h):
    l_cnt = 0
    for x in range(w):
        ls[y][x] = l_cnt
        if cells[y][x] == '.':
            l_cnt += 1
        else:
            l_cnt = 0

    r_cnt = 0
    for x in range(w - 1, -1, -1):
        rs[y][x] = r_cnt
        if cells[y][x] == '.':
            r_cnt += 1
        else:
            r_cnt = 0

maxv = 0
for y in range(h):
    for x in range(w):
        if cells[y][x] == '#':
            continue
        maxv = max(maxv, us[y][x] + ds[y][x] + ls[y][x] +
                   rs[y][x] + (1 if cells[y][x] == '.' else 0))
print(maxv)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

H,W = map(int,input().split())
grid = np.zeros((H+2,W+2), dtype=bool)
grid[1:-1, 1:-1] = tuple(tuple(map(lambda c: c != '#', input())) for _ in range(H))

scores = np.zeros((H+2, W+2), dtype=int)

for i in range(1, H+1):
    s = 0
    for j in range(1,W+1):
        if grid[i,j]:
            scores[i,j] += s
            s += 1
        else:
            s = 0

for i in range(1, H+1):
    s = 0
    for j in reversed(range(1,W+1)):
        if grid[i,j]:
            scores[i,j] += s
            s += 1
        else:
            s = 0

for j in range(1, W+1):
    s = 0
    for i in range(1,H+1):
        if grid[i,j]:
            scores[i,j] += s
            s += 1
        else:
            s = 0

for j in range(1, W+1):
    s = 0
    for i in reversed(range(1,H+1)):
        if grid[i,j]:
            scores[i,j] += s
            s += 1
        else:
            s = 0


print(scores.max()+1)

Submission status: Time Limit Exceeded

Solution code:
H,W=map(int,input().split())
MAP=["#"*(W+2)]+["#"+input()+"#" for i in range(H)]+["#"*(W+2)]
yoko=[[0]*(W+2) for i in range(H+2)]
tate=[[0]*(H+2) for i in range(W+2)]
for w in range(1,1+W):
    if MAP[1][w]==".":
        tate[w][1]=1
for h in range(1,1+H):
    if MAP[h][1]==".":
        yoko[h][1]=1
    for w in range(1,1+W):
        if MAP[h][w+1]==".":
            yoko[h][w+1]=yoko[h][w]+1
        else:
            x=yoko[h][w]
            yoko[h][w-x+1:w+1]=[x]*x
        if MAP[h+1][w]==".":
            tate[w][h+1]=tate[w][h]+1
        else:
            x=tate[w][h]
            tate[w][h-x+1:h+1]=[x]*x
ans=0
for h in range(1,1+H):
    for w in range(1,1+W):
        ans=max(ans,yoko[h][w]+tate[w][h]-1)
        #print(yoko[h][w],tate[w][h])
print(ans)

Submission status: Time Limit Exceeded

Solution code:
H, W = map( int, input().split())
S = [ input() for _ in range(H)]
T = [ [1]*W for _ in range(H)]
Y = [ [1]*W for _ in range(H) ]
for i in range(H):
    now = 0
    cnt = 0
    for j in range(W):
        if S[i][j] == ".":
            cnt += 1
        else:
            for k in range(now, j):
                T[i][k] = cnt
            cnt = 0
            now = j+1
        if cnt > 0:
            for k in range(now, W):
                T[i][k] = cnt
            
for i in range(W):
    now = 0
    cnt = 0
    for j in range(H):
        if S[j][i] == ".":
            cnt += 1
        else:
            for k in range(now, j):
                Y[k][i] = cnt
            cnt = 0
            now = j+1
        if cnt > 0:
            for k in range(now, H):
                Y[k][i] = cnt

ans = 0
for i in range(H):
    for j in range(W):
        if ans < T[i][j] + Y[i][j]-1:
            ans = T[i][j] + Y[i][j]-1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import sys
sys.setrecursionlimit(2500)
H, W = map(int, input().split())
S = ['#'*(W+2)]+['#' + input() + '#' for _ in range(H)]+['#'*(W+2)]

ans = [[None] * (W+2) for _ in range(H+2)]
ansX = [[None] * (W+2) for _ in range(H+2)]
ansY = [[None] * (W+2) for _ in range(H+2)]

def process(n, x, y, dx, dy):
  ret = 0
  if S[y][x] == '#':
    ret = n
  else:
    ret = process(n+1, x+dx, y+dy, dx, dy)
  if dx > 0:
    ansX[y][x] = ret
  else:
    ansY[y][x] = ret
  return ret

final = 0
for y in range(1, H+1):
  for x in range(1, W+1):
    if S[y][x] == '#':
      continue
    if ansX[y][x] is None:
      process(0, x, y, 1, 0)
    if ansY[y][x] is None:
      process(0, x, y, 0, 1)
    ans = ansX[y][x] + ansY[y][x] - 1
    final = ans if ans > final else final
print(final)

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
from sys import stdin
import numpy as np
# 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)
v_cum_S = np.zeros((H, W), dtype=int)
h_cum_S = np.zeros((H, W), dtype=int)
for i in range(W):
    start = 0
    target = np.arange(H)[S[:, i] == 0]
    for t in target:
        v_cum_S[start: t, i] = S[start:t, i].sum()
        start = t+1
    v_cum_S[start:, i] = S[start:, i].sum()

for i in range(H):
    start = 0
    target = np.arange(W)[S[i, :] == 0]
    for t in target:
        h_cum_S[i, start: t] = S[i, start:t].sum()
        start = t+1
    h_cum_S[i, start:] = S[i, start:].sum()

ans = 0
for i in range(H):
    for j in range(W):
        if S[i, j] == 0:
            continue
        else:
            ans = max(ans, v_cum_S[i, j] + h_cum_S[i, j] - 1)


# print(S)
# print(v_cum_S)
# print(h_cum_S)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
H, W = map( int, input().split())
S = [ input() for _ in range(H)]
T = [ [1]*W for _ in range(H)]
Y = [ [1]*W for _ in range(H) ]
for i in range(H):
    now = 0
    cnt = 0
    for j in range(W):
        if S[i][j] == ".":
            cnt += 1
        else:
            for k in range(now, j):
                T[i][k] = cnt
            cnt = 0
            now = j+1
        if cnt > 0:
            for k in range(now, W):
                T[i][k] = cnt
            
for i in range(W):
    now = 0
    cnt = 0
    for j in range(H):
        if S[j][i] == ".":
            cnt += 1
        else:
            for k in range(now, j):
                Y[k][i] = cnt
            cnt = 0
            now = j+1
        if cnt > 0:
            for k in range(now, H):
                Y[k][i] = cnt

ans = 0
for i in range(H):
    for j in range(W):
        if ans < T[i][j] + Y[i][j]-1:
            ans = T[i][j] + Y[i][j]-1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

H,W = map(int,input().split())
grid = np.zeros((H+2,W+2), dtype=bool)
grid[1:-1, 1:-1] = tuple(tuple(map(lambda c: c != '#', input())) for _ in range(H))
grid = grid.tolist()

scores = [[0]*(W+2) for _ in range(H+2)]

for i in range(1, H+1):
    s = 0
    for j in range(1,W+1):
        if grid[i][j]:
            scores[i][j] += s
            s += 1
        else:
            s = 0

for i in range(1, H+1):
    s = 0
    for j in reversed(range(1,W+1)):
        if grid[i][j]:
            scores[i][j] += s
            s += 1
        else:
            s = 0

for j in range(1, W+1):
    s = 0
    for i in range(1,H+1):
        if grid[i][j]:
            scores[i][j] += s
            s += 1
        else:
            s = 0

for j in range(1, W+1):
    s = 0
    for i in reversed(range(1,H+1)):
        if grid[i][j]:
            scores[i][j] += s
            s += 1
        else:
            s = 0


print(np.array(scores).max()+1)

Submission status: Time Limit Exceeded

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

tate = [[0 for i in range(w)] for k in range(h)]
yoko = [[0 for i in range(w)] for k in range(h)]
for i in range(h):
    temp = list(input())
    s.append(temp)
    counter = 0
    start = 0
    for k in range(w):
        if temp[k] == ".":
            counter += 1
            if k == w-1:
                for j in range(start,k+1):
                    yoko[i][j] = counter
        else:
            for j in range(start,k):
                yoko[i][j] = counter
            start = k+1
            counter = 0

for i in range(w):
    counter = 0
    start = 0
    for k in range(h):
        if s[k][i] == ".":
            counter += 1
            if k == h-1:
                for j in range(start,k+1):
                    tate[j][i] = counter
        else:
            for j in range(start,k):
                tate[j][i] = counter
            start = k+1
            counter = 0

ans = 0
for i in range(h):
    for k in range(w):
        if yoko[i][k] != 0 and tate[i][k] != 0:
            if yoko[i][k]+tate[i][k]-1 > ans:
                ans = yoko[i][k]+tate[i][k]-1

print(ans)

Submission status: Time Limit Exceeded

Solution code:
h,w=map(int,input().split())
hf=[[0 for i in range(w)]for i in range(h)]
vf=[[0 for i in range(w)]for i in range(h)]
field=[]
for i in range(h):
    field.append(list(input()))
for i in range(h):
    tmp=0
    for j in range(w):
        if field[i][j]=='.':
            tmp+=1
            hf[i][j]=tmp
        else:
            tmp=0
    tmp=0
    for j in range(w):
        j=w-j-1
        if field[i][j]=='.':
            if tmp == 0:
                tmp=hf[i][j]
            else:
                hf[i][j]=tmp
        else:
            tmp=0
for j in range(w):
    tmp=0
    for i in range(h):
        if field[i][j]=='.':
            tmp+=1
            vf[i][j]=tmp
        else:
            tmp=0
    tmp=0
    for i in range(h):
        i=h-i-1
        if field[i][j]=='.':
            if tmp == 0:
                tmp=vf[i][j]
            else:
                vf[i][j]=tmp
        else:
            tmp=0
mx=0
for i in range(h):
    for j in range(w):
        if hf[i][j]+vf[i][j]>mx:
            mx=hf[i][j]+vf[i][j]
print(mx-1)

Submission status: Time Limit Exceeded

Solution code:

MOD = int(1e9) + 7

def main():
    buf = input()
    buflist = buf.split()
    H = int(buflist[0])
    W = int(buflist[1])
    S = []
    for i in range(H):
        buf = input()
        S.append(buf)
    lightmap_h = []
    for i in range(H):
        lightmap_h.append([])
        for j in range(W):
            lightmap_h[i].append(0)
    lightmap_v = []
    for j in range(H):
        lightmap_v.append([])
        for i in range(W):
            lightmap_v[j].append(0)
    for i in range(H):
        light_count = 0
        last_pointer = 0
        for j in range(W):
            if S[i][j] == '.':
                light_count += 1
            else:
                for k in range(last_pointer, j):
                    lightmap_h[i][k] = light_count
                light_count = 0
                last_pointer = j+1
        for k in range(last_pointer, W):
            lightmap_h[i][k] = light_count
    for j in range(W):
        light_count = 0
        last_pointer = 0
        for i in range(H):
            if S[i][j] == '.':
                light_count += 1
            else:
                for k in range(last_pointer, i):
                    lightmap_v[k][j] = light_count
                light_count = 0
                last_pointer = i+1
        for k in range(last_pointer, H):
            lightmap_v[k][j] = light_count
    maximum = 0
    for i in range(H):
        for j in range(W):
            hor = lightmap_h[i][j]
            vert = lightmap_v[i][j]
            if hor == 0 or vert == 0:
                continue
            light_distance = hor + vert - 1
            if light_distance > maximum:
                maximum = light_distance
    print(maximum)

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
H, W = map(int, input().split())
B = [input() for _ in range(H)]
board = np.zeros((H, W), dtype=int)
for r, row in enumerate(B):
    for c, col in enumerate(row):
        board[r][c] = 1 if col == "." else 0
cnt = np.zeros((H, W), dtype=int)
cnt[:, :] = 1

for _ in range(4):
    R, C = cnt.shape
    for c in range(C):
        now = 0
        for r in range(R):
            if board[r][c]:
                cnt[r][c] += now
                now += 1
            else:
                now = 0
    board = np.rot90(board, k=-1)
    cnt = np.rot90(cnt, k=-1)
print(np.max(cnt))

Submission status: Time Limit Exceeded

Solution code:
h,w = map(int,input().split())
s = [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):
  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):
    if s[i][(w-1)-j] == "#":
      r[i][(w-1)-j] = 0
    elif j == 0:
      r[i][(w-1)-j] = 1
    else:
      r[i][(w-1)-j] = r[i][w-j] + 1


for j in range(w):
  for i in range(h):
    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 j in range(w):
  for i in range(h):
    if s[(h-1)-i][j] == "#":
      d[(h-1)-i][j] = 0
    elif i == 0:
      d[(h-1)-i][j] = 1
    else:
      d[(h-1)-i][j] = d[h-i][j] + 1

m = 3
for i in range(h):
  for j in range(w):
    m = max(m, l[i][j] + r[i][j] + u[i][j] + d[i][j]) 
print(m-3)

#print(d)

Submission status: Time Limit Exceeded

Solution code:
h, w = list(map(int, input().split()))
grid = []
posi = []
for i in range(h):
	grid.append(input())
	np = []
	pre = -1
	for j in range(w):
		if grid[i][j] == '#':
			pre = j
		np.append([pre, 0])
	pre = w
	for j in range(w - 1, -1, -1):
		if grid[i][j] == '#':
			pre = j
		np[j][0] = pre - np[j][0] - 1
	posi.append(np)
for j in range(w):
	pre = h
	for i in range(h - 1, -1, -1):
		if grid[i][j] == '#':
			pre = i
		posi[i][j][1] = pre
	pre = -1
	for i in range(h):
		if grid[i][j] == '#':
			pre = i
		posi[i][j][1] -= pre + 1
ans = 0
for i in range(h):
	res = ""
	for j in range(w):
		res += "(%2d, %2d) " % (posi[i][j][0], posi[i][j][1])
		ans = max(ans, sum(posi[i][j]) - 1)
	# print(res)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
H,W=map(int,input().split())
L=[]
l=["#" for i in range(W+2)]
L.append(l)
for i in range(H):
    s=list(input())
    s=["#"]+s+["#"]
    L.append(s)
L.append(s)

#print(L)
A=[[[0,0,0,0]for i in range(W+2)]for j in range(H+2)]
#print(A)
for i in range(1,H+1):
    for j in range(1,W+1):
        if L[i][j]==".":
            A[i][j][0]=A[i][j-1][0]+1
            A[i][j][1]=A[i-1][j][1]+1
#print(A)
for i in range(1,H+1):
    for j in range(1,W+1):
        if L[H+1-i][W+1-j]==".":
            A[H+1-i][W+1-j][2]=A[H+1-i][W+2-j][2]+1
            A[H+1-i][W+1-j][3]=A[H+2-i][W+1-j][3]+1
#print(A)
ANS=0
for i in range(1,H+1):
    for j in range(1,W+1):
        if (sum(A[i][j])-3)>ANS:
            ANS=(sum(A[i][j])-3)
print(ANS)

Submission status: Time Limit Exceeded

Solution code:
H, W = map(int, input().split())
s = [input() for _ in range(H)]
tate = [[0 for _ in range(W)] for _ in range(H)]
yoko = [[0 for _ in range(W)] for _ in range(H)]
for h in range(H):
	ba, fr = 0, 0
	while ba < W:
		if s[h][ba] == "#":
			ba += 1
			fr += 1
		while fr < W and s[h][fr] == ".":
			fr += 1
		for w in range(ba, fr):
			yoko[h][w] = fr-ba
		ba = fr
#print(yoko, sep="\n")
for w in range(W):
	ba, fr = 0, 0
	while ba < H:
		if s[ba][w] == "#":
			ba += 1
			fr += 1
		while fr < H and s[fr][w] == ".":
			fr += 1
		for h in range(ba, fr):
			tate[h][w] = fr-ba
		ba = fr
#print(tate, sep="\n")
ans = 1
for h in range(H):
	for w in range(W):
		ans = max(ans, yoko[h][w]+tate[h][w]-1)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
#import numpy as np
#from numpy import*
#from scipy.sparse.csgraph import shortest_path #shortest_path(csgraph=graph) # dijkstra# floyd_warshall
#from scipy.sparse import csr_matrix

from collections import* #defaultdict Counter deque appendleft
from fractions import gcd
from functools import* #reduce
from itertools import* #permutations("AB",repeat=2) combinations("AB",2) product("AB",2) groupby accumulate
from operator import mul,itemgetter
from bisect import* #bisect_left bisect_right
from heapq import* #heapify heappop heappushpop
from math import factorial,pi
from copy import deepcopy
import sys
sys.setrecursionlimit(10**8)
input=sys.stdin.readline  #危険！基本オフにしろ！

def main():
    n,m=map(int,input().split())
    grid=[list(input())for i in range(n)]
    ans=[]
    for y in range(n):
        for x in range(m):
            if grid[y][x]==".":
                #print(y,x)
                tmp=1
                upper=[grid[i][x]for i in range(y)][::-1]
                lower=[grid[i][x]for i in range(y+1,n)]
                left =[grid[y][i]for i in range(x)][::-1]
                right=[grid[y][i]for i in range(x+1,m)]
                #print(upper,lower,left,right)
                for i in (upper,lower,left,right):
                    if len(i)>0:
                        for j in i:
                            if j==".":
                                tmp+=1
                            else:
                                break
                ans.append(tmp)
    print(max(ans))
if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
H, W = map(int, input().split())
X = [[0]*W for _ in range(H)]
Y = [[0]*W for _ in range(H)]
S = [input() for _ in range(H)]
for y, s in enumerate(S):
    for x, c in enumerate(s):
        if c==".":
            X[y][x] = X[y][x-1] + 1
    vp = X[y][-1]

    for x in range(W-2, -1, -1):
        v = X[y][x]
        if v != 0:
            v = X[y][x] = max(v, vp)
        vp = v

for x in range(W):
    for y in range(H):
        c = S[y][x]
        if c==".":
            Y[y][x] = Y[y-1][x] + 1

    vp = Y[-1][x]
    for y in range(H-2, -1, -1):
        v = Y[y][x]
        if v != 0:
            v = Y[y][x] = max(v, vp)
        vp = v

ans = 0
for x, y in zip(X, Y):
    for xx, yy in zip(x, y):
        ans = max(ans, xx+yy)
print(ans-1)

Submission status: Time Limit Exceeded

Solution code:
#import numpy as np
#from numpy import*
#from scipy.sparse.csgraph import shortest_path #shortest_path(csgraph=graph) # dijkstra# floyd_warshall
#from scipy.sparse import csr_matrix

from collections import* #defaultdict Counter deque appendleft
from fractions import gcd
from functools import* #reduce
from itertools import* #permutations("AB",repeat=2) combinations("AB",2) product("AB",2) groupby accumulate
from operator import mul,itemgetter
from bisect import* #bisect_left bisect_right
from heapq import* #heapify heappop heappushpop
from math import factorial,pi
from copy import deepcopy
import sys
sys.setrecursionlimit(10**8)
#input=sys.stdin.readline  #危険！基本オフにしろ！

import numpy as np 
r,c=map(int,input().split())
s=np.array([list(input())for i in range(r)])=="."
s=s.astype(int)
def f(a):
    ar=[1]*len(a)
    if a[0]==0:
        ar[0]=0
    for i in range(1,len(a)):
        if a[i]>0:
            ar[i]=ar[i-1]+1
        else:
            ar[i]=0
    return ar

ans=0
m=np.array([f(s[i])               for i in range(r)])
h=np.array([f(s[i][::-1])[::-1]   for i in range(r)])
u=np.array([f(s[:,i])             for i in range(c)]).T.reshape(r,c)
s=np.array([f(s[:,i][::-1])       for i in range(c)]).T[::-1].reshape(r,c)
print(np.max(m+h+u+s)-3)

Submission status: Time Limit Exceeded

Solution code:
h,w=map(int,input().split())
sl=[input() for i in range(h)]
ans=0
for i in range(h):
    for j in range(w):
        if sl[i][j]!='#':
            cnt=1
            for k in range(i-1,-1,-1):
                if sl[k][j]=='.':
                    cnt+=1
                else:
                    break
            for k in range(i+1,h):
                if sl[k][j]=='.':
                    cnt+=1
                else:
                    break
            for k in range(j-1,-1,-1):
                if sl[i][k]=='.':
                    cnt+=1
                else:
                    break
            for k in range(j+1,w):
                if sl[i][k]=='.':
                    cnt+=1
                else:
                    break
            ans=max(ans,cnt)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
h, w = map(int, input().split())
s = [input() for _ in range(h)]
hor = [[0] * w for _ in range(h)]
ver = [[0] * w for _ in range(h)]

for i in range(h):
    now = 0
    for j in range(w):
        if s[i][j] == '#':
            now = 0
        else:
            now += 1
            hor[i][j] = now

for j in range(w):
    now = 0
    for i in range(h):
        if s[i][j] == '#':
            now = 0
        else:
            now += 1
            ver[i][j] = now

for i in range(h-1, -1, -1):
    now = 0
    for j in range(w-1, -1, -1):
        if s[i][j] == '#':
            now = 0
        else:
            now = max(now, hor[i][j])
            hor[i][j] = now

for j in range(w-1, -1, -1):
    now = 0
    for i in range(h-1, -1, -1):
        if s[i][j] == '#':
            now = 0
        else:
            now = max(now, ver[i][j])
            ver[i][j] = now

res = 0
for i in range(h):
    for j in range(w):
        res = max(hor[i][j] + ver[i][j] - 1, res)
print(res)

Submission status: Time Limit Exceeded

Solution code:
H, W = map(int, input().split())
lst = [['#'] * (W+2)]
lst += [['#'] + list(input()) + ['#'] for i in range(H)]
lst += [['#'] * (W+2)]

def ue(i, j):
    count = 0
    for k in range(1,H+1):
        if lst[i-k][j] == '#':
            return count
        else:
            count += 1

def shita(i, j):
    count = 0
    for k in range(1, H+1):
        if lst[i+k][j] == '#':
            return count
        else:
            count += 1

def hidari(i, j):
    count = 0
    for k in range(1,W+1):
        if lst[i][j-k] == '#':
            return count
        else:
            count += 1

def migi(i, j):
    count = 0
    for k in range(1,W+1):
        if lst[i][j+k] == '#':
            return count
        else:
            count += 1

ans = 0
for i in range(1,H+1):
    for j in range(1, W+1):
        if lst[i][j] != '#':
            # print (i,j, 1 + ue(i,j)+shita(i,j)+hidari(i,j)+migi(i,j))
            ans = max(ans, 1 + ue(i,j)+shita(i,j)+hidari(i,j)+migi(i,j))

print (ans)

Submission status: Time Limit Exceeded

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

def score(y, x):
	if STAGE[y][x] == "#":
		return 0
	s = 1
	for n in range(y + 1, H):
		if STAGE[n][x] == ".":
			s += 1
		else:
			break
	for n in range(y - 1, -1, -1):
		if STAGE[n][x] == ".":
			s += 1
		else:
			break
	for n in range(x + 1, W):
		if STAGE[y][n] == ".":
			s += 1
		else:
			break
	for n in range(x - 1, -1, -1):
		if STAGE[y][n] == ".":
			s += 1
		else:
			break
	return s

result = 0
for y in range(H):
	for x in range(W):
		result = max(result, score(y, x))

print(result)

Submission status: Time Limit Exceeded

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

dp1 = [[0 for _ in range(W)] for _ in range(H)]
dp2 = [[0 for _ in range(W)] for _ in range(H)]

for i in range(H):
    for j in range(W):
        if dp1[i][j] == 0 and S[i][j] == '.':
            c = 0
            for k in range(i, H):
                if S[k][j] == '.':
                    c += 1
                else:
                    break
            for k in range(i, H):
                if S[k][j] == '.':
                    dp1[k][j] = c
                else:
                    break
for i in range(H):
    for j in range(W):
        if dp2[i][j] == 0 and S[i][j] == '.':
            c = 0
            for k in range(j, W):
                if S[i][k] == '.':
                    c += 1
                else:
                    break
            for k in range(j, W):
                if S[i][k] == '.':
                    dp2[i][k] = c
                else:
                    break

ans = max(
    dp1[i][j] + dp2[i][j] - 1
    for i in range(H)
    for j in range(W)
)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
from bisect import bisect
H,W=map(int,input().split())
S=[input() for i in range(H)]
sec_x=[[-1] for i in range(H)]
sec_y=[[-1] for i in range(W)]
for y in range(H):
  for x in range(W):
    if S[y][x]=="#": 
      sec_x[y].append(x)
  sec_x[y].append(W)
for x in range(W):
  for y in range(H):
    if S[y][x]=="#": 
      sec_y[x].append(y)
  sec_y[x].append(H)

ans=0
#print(sec_x)
#print(sec_y)
for y in range(H):
  for x in range(W):
    if S[y][x]!="#":
      a=bisect(sec_x[y],x)
      b=bisect(sec_y[x],y)
      #print(x,y,a,b,sec_x[y][a]-sec_x[y][a-1]+sec_y[x][b]-sec_y[x][b-1]-3)
      ans=max(ans,sec_x[y][a]-sec_x[y][a-1]+sec_y[x][b]-sec_y[x][b-1]-3)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
#import numpy as np
#from numpy import*
#from scipy.sparse.csgraph import shortest_path #shortest_path(csgraph=graph) # dijkstra# floyd_warshall
#from scipy.sparse import csr_matrix

from collections import* #defaultdict Counter deque appendleft
from fractions import gcd
from functools import* #reduce
from itertools import* #permutations("AB",repeat=2) combinations("AB",2) product("AB",2) groupby accumulate
from operator import mul,itemgetter
from bisect import* #bisect_left bisect_right
from heapq import* #heapify heappop heappushpop
from math import factorial,pi
from copy import deepcopy
import sys
sys.setrecursionlimit(10**8)
#input=sys.stdin.readline  #危険！基本オフにしろ！

def main():
    n,m=map(int,input().split())
    grid=[list(input())for i in range(n)]
    ans=[]
    for y in range(n):
        for x in range(m):
            if grid[y][x]==".":
                #print(y,x)
                tmp=1
                upper=[grid[i][x]for i in range(y)][::-1]
                lower=[grid[i][x]for i in range(y+1,n)]
                left =[grid[y][i]for i in range(x)][::-1]
                right=[grid[y][i]for i in range(x+1,m)]
                #print(upper,lower,left,right)
                for i in (upper,lower,left,right):
                    if len(i)>0:
                        for j in i:
                            if j==".":
                                tmp+=1
                            else:
                                break
                ans.append(tmp)
    print(max(ans))
if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
import sys

h, w = list(map(int, input().split()))
field = [line.rstrip() for line in sys.stdin]

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

for i, row in enumerate(field, start=1):
    for j, c in enumerate(row, start=1):
        l[i][j] = l[i][j - 1] + 1 if c == '.' else 0
        u[i][j] = u[i - 1][j] + 1 if c == '.' else 0
for i, row in reversed(list(enumerate(field, start=1))):
    for j, c in reversed(list(enumerate(row, start=1))):
        d[i][j] = d[i + 1][j] + 1 if c == '.' else 0
        r[i][j] = r[i][j + 1] + 1 if c == '.' else 0


ans = 0
for ll, rr, uu, dd in zip(l, r, u, d):
    ans = max(ans, max(map(sum, zip(ll, rr, uu, dd))))
print(ans - 3)

Submission status: Accepted

Solution code:
#写経AC
import numpy as np
H,W = map(int,input().split())
L = np.zeros((H,W),int)
R = np.zeros((H,W),int)
D = np.zeros((H,W),int)
U = np.zeros((H,W),int)
S = np.array([list(input()) for h in range(H)])=="."

for h in range(H):
  U[h] = S[h]*(U[h-1]+1)
  D[-h-1] = S[-h-1]*(D[-h]+1)

for w in range(W):
  L[:,w] = S[:,w]*(L[:,w-1]+1)
  R[:,-w-1] = S[:,-w-1]*(R[:,-w]+1)

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