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:
def main():
    h,*s=open(0)
    s=[tuple(t[:-1])for t in s]
    h,w=map(int,h.split())
    a=tuple([0]*w for _ in range(h))
    b=tuple([0]*w for _ in range(h))
    c=tuple([0]*h for _ in range(w))
    d=tuple([0]*h for _ in range(w))
    for t,x,y in zip(s,a,b):
        x[0]=int(t[0]=='.')
        for i,u in enumerate(t[1:]):
            x[i+1]=x[i]+1if u=='.'else 0
        y[-1]=int(t[-1]=='.')
        for i,u in enumerate(t[-2::-1],1):
            y[~i]=y[-i]+1if u=='.'else 0
    for t,x,y in zip(zip(*s),c,d):
        x[0]=int(t[0]=='.')
        for i,u in enumerate(t[1:]):
            x[i+1]=x[i]+1if u=='.'else 0
        y[-1]=int(t[-1]=='.')
        for i,u in enumerate(t[-2::-1],1):
            y[~i]=y[-i]+1if u=='.'else 0
    print(max(sum(u)-3for t in zip(a,b,tuple(zip(*c)),tuple(zip(*d)))for u in zip(*t)))
main()

Submission status: Time Limit Exceeded

Solution code:
from pprint import pprint
from collections import deque
h, w = map(int, input().split())

m = deque([])
mv = deque([])
mh = deque([])

for i in range(h):
    mh.append(deque([0] * w))
for i in range(h):
    mv.append(deque([0] * w))

for i in range(h):
    m.append(input())

for i in range(h):
    c = 0
    for j in range(w):
        if m[i][j] == "#":
            mh[i][j] = 0
            for k in range(c):
                mh[i][j - k - 1] = c
            c = 0
        else:
            c += 1
    for k in range(c):
        mh[i][w - 1 - k] = c

for i in range(w):
    c = 0
    for j in range(h):
        if m[j][i] == "#":
            mv[j][i] = 0
            for k in range(c):
                mv[j - k - 1][i] = c
            c = 0
        else:
            c += 1
    for k in range(c):
        mv[h - 1 - k][i] = c

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


#pprint(mh)
#pprint(mv)

Submission status: Time Limit Exceeded

Solution code:
H,W=map(int,input().split())
S=[]
for h in range(H):
    Sh=list(input())
    S.append(Sh)
    
L=[[0 for w in range(W)] for h in range(H)]
R=[[0 for w in range(W)] for h in range(H)]
U=[[0 for w in range(W)] for h in range(H)]
D=[[0 for w in range(W)] for h in range(H)]

for h in range(H):
    a=0
    b=0
    for w in range(W):
        if S[h][w]=='.':
            a+=1
        if S[h][w]=='#':
            a=0
        if S[h][-(1+w)]=='.':
            b+=1
        if S[h][-(1+w)]=='#':
            b=0
        L[h][w]+=a
        R[h][-(1+w)]+=b

for w in range(W):
    a=0
    b=0
    for h in range(H):
        if S[h][w]=='.':
            a+=1
        if S[h][w]=='#':
            a=0
        if S[-(1+h)][w]=='.':
            b+=1
        if S[-(1+h)][w]=='#':
            b=0
        U[h][w]+=a
        D[-(1+h)][w]+=b

maxScore=0
for h in range(H):
    for w in range(W):
        score=L[h][w]+R[h][w]+U[h][w]+D[h][w]-3
        if score>maxScore:
            maxScore=score

print(maxScore)

Submission status: Time Limit Exceeded

Solution code:
import sys
import numpy as np
sys.setrecursionlimit(10 ** 5)


def LI(): return [int(x) for x in sys.stdin.readline().split()]


def main():
    H, W = LI()
    S = np.ones((H, W))
    for i in range(H):
        str = input()
        for j, s in enumerate(str):
            if s == '#':
                S[i][j] = 0

    L = S.copy()
    R = S.copy()
    U = S.copy()
    D = S.copy()
    for i in range(H):
        for j in range(1, W):
            if S[i][j]:
                L[i][j] = L[i][j-1] + 1
            if S[i][W-j-1]:
                R[i][W-j-1] = R[i][W-j] + 1

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

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


main()

Submission status: Time Limit Exceeded

Solution code:
from pprint import pprint
from collections import deque
h, w = map(int, input().split())

m = deque([])
mv = deque([])
mh = deque([])

for i in range(h):
    mh.append([0] * w)
for i in range(h):
    mv.append([0] * w)

for i in range(h):
    m.append(input())

for i in range(h):
    c = 0
    for j in range(w):
        if m[i][j] == "#":
            mh[i][j] = 0
            for k in range(c):
                mh[i][j - k - 1] = c
            c = 0
        else:
            c += 1
    for k in range(c):
        mh[i][w - 1 - k] = c

for i in range(w):
    c = 0
    for j in range(h):
        if m[j][i] == "#":
            mv[j][i] = 0
            for k in range(c):
                mv[j - k - 1][i] = c
            c = 0
        else:
            c += 1
    for k in range(c):
        mv[h - 1 - k][i] = c

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

Submission status: Time Limit Exceeded

Solution code:
n,m=map(int,input().split())
l=[["#" for i in range(m+2)]]
for i in range(n):
  l.append(["#"]+list(input())+["#"])
l.append(["#" for i in range(m+2)])
llist=[[0 for i in range(m+2)] for i in range(n+2)]
rlist=[[0 for i in range(m+2)] for i in range(n+2)]
dlist=[[0 for i in range(m+2)] for i in range(n+2)]
ulist=[[0 for i in range(m+2)] for i in range(n+2)]
for i in range(m+2):
  for j  in range(n+2):
    if i==0 or j==0 or i==m+1 or j==n+1 or l[j][i]=="#":
      llist[j][i]=0
    elif l[j][i]==".":
      llist[j][i]=1+llist[j][i-1]
for i in range(m+2):
  for j  in range(n+2):
    if i==0 or j==0 or i==m+1 or j==n+1 or l[j][i]=="#":
      ulist[j][i]=0
    elif l[j][i]==".":
      ulist[j][i]=1+ulist[j-1][i]
for i in range(m+2):
  for j  in range(n+2):
    if i==0 or j==0 or i==m+1 or j==n+1 or l[j][m+1-i]=="#":
      rlist[j][m+1-i]=0
    elif l[j][m+1-i]==".":
      rlist[j][m+1-i]=1+rlist[j][m+2-i]
for i in range(m+2):
  for j  in range(n+2):
    if i==0 or j==0 or i==m+1 or j==n+1 or l[n+1-j][i]=="#":
      dlist[n+1-j][i]=0
    elif l[n+1-j][i]==".":
      dlist[n-j+1][i]=1+dlist[n-j+2][i]
c=0
for i in range(1,m+1):
  for j in range(1,n+1):
    c1=llist[j][i]+rlist[j][i]+ulist[j][i]+dlist[j][i]-3
    if c<c1:
      c=c1
print(c)

Submission status: Time Limit Exceeded

Solution code:
H,W=map(int,input().split())
S=[]
for h in range(H):
    Sh=list(input())
    S.append(Sh)
    
L=[[0 for w in range(W)] for h in range(H)]
R=[[0 for w in range(W)] for h in range(H)]
U=[[0 for w in range(W)] for h in range(H)]
D=[[0 for w in range(W)] for h in range(H)]

for h in range(H):
    a=0
    for w in range(W):
        if S[h][w]=='.':
            a+=1
        else:
            a=0
        L[h][w]+=a

for h in range(H):
    a=0
    for w in range(W):
        if S[h][-(1+w)]=='.':
            a+=1
        else:
            a=0
        R[h][-(1+w)]+=a

for w in range(W):
    a=0
    for h in range(H):
        if S[h][w]=='.':
            a+=1
        else:
            a=0
        U[h][w]+=a
    
for w in range(W):
    a=0
    for h in range(H):
        if S[-(1+h)][w]=='.':
            a+=1
        else:
            a=0
        D[-(1+h)][w]+=a

maxScore=0
for h in range(H):
    for w in range(W):
        score=L[h][w]+R[h][w]+U[h][w]+D[h][w]-3
        if score>maxScore:
            maxScore=score

print(maxScore)

Submission status: Time Limit Exceeded

Solution code:
h,*s=open(0)
s=[tuple(t[:-1])for t in s]
h,w=map(int,h.split())
a,b,c,d=[],[],[],[]
for t in s:
    e=[t[0]=='.']
    for u in t[1:]:
        e.append(-~e[-1]*(u=='.'))
    a.append(tuple(e))
    e=[t[-1]=='.']
    for u in t[-2::-1]:
        e.append(-~e[-1]*(u=='.'))
    b.append(tuple(e[::-1]))
for t in zip(*s):
    e=[t[0]=='.']
    for u in t[1:]:
        e.append(-~e[-1]*(u=='.'))
    c.append(tuple(e))
    e=[t[-1]=='.']
    for u in t[-2::-1]:
        e.append(-~e[-1]*(u=='.'))
    d.append(tuple(e[::-1]))
print(max(sum(u)-3for t in zip(a,b,tuple(zip(*c)),tuple(zip(*d)))for u in zip(*t)))

Submission status: Time Limit Exceeded

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

import sys

h,w = [ int(x) for x in sys.stdin.readline().split() ]
masu = [ ["" for _ in range(w)] for _ in range(h)  ]
for i in range(h):
    row = sys.stdin.readline()
    for j in range(w): masu[i][j]= row[j]
#
# l, r
w1 = w - 1
l= [ [ 0 for _ in range(w) ] for _ in range(h) ]
r= [ [ 0 for _ in range(w) ] for _ in range(h) ]
for i in range(h):
    for j in range(w):
        if masu[i][j]=="#": l[i][j]= 0
        elif j==0: l[i][j]= 1
        else: l[i][j]= l[i][j-1] + 1
    #
    for j in range(w1,-1,-1):
        if masu[i][j]=="#": r[i][j]= 0
        elif j==w1: r[i][j]= 1
        else: r[i][j]= r[i][j+1] + 1
#
# u, d
h1= h - 1
u= [ [ 0 for _ in range(w) ] for _ in range(h) ]
d= [ [ 0 for _ in range(w) ] for _ in range(h) ]
for j in range(w):
    for i in range(h):
        if masu[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(h1,-1,-1):
        if masu[i][j]=="#": d[i][j]= 0
        elif i==h1: d[i][j]= 1
        else: d[i][j]= d[i+1][j] + 1
#
mv= 0
for i in range(h):
    for j in range(w):
        if masu[i][j]=="#": continue
        tmp= l[i][j] + r[i][j] + u[i][j] + d[i][j] - 3
        if tmp>mv: mv= tmp
#
print( mv )

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
import numpy as np

H, W = map(int, input().split())
S = [input() for x in range(H)]

L = []
R = []
U = []
D = []
for h in range(H):
    ltmp = []
    rtmp = []
    utmp = []
    dtmp = []
    for w in range(W):
        lcnt = 0
        rcnt = 0
        ucnt = 0
        dcnt = 0
        if S[h][w] != '#':
            for i in range(w, W):
                if S[h][i] == '.':
                    rcnt += 1
                else:
                    break
            for i in range(w, -1, -1):
                if S[h][i] == '.':
                    lcnt += 1
                else:
                    break
            for i in range(h, H):
                if S[i][w] == '.':
                    dcnt += 1
                else:
                    break
            for i in range(h, -1, -1):
                if S[i][w] == '.':
                    ucnt += 1
                else:
                    break
        ltmp.append(lcnt)
        rtmp.append(rcnt)
        utmp.append(ucnt)
        dtmp.append(dcnt)
    L.append(ltmp)
    R.append(rtmp)
    U.append(utmp)
    D.append(dtmp)

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

Submission status: Time Limit Exceeded

Solution code:
def d_lamp(H, W, Grid):
    num_left = [[0] * W for _ in range(H)]
    num_right = [[0] * W for _ in range(H)]
    num_down = [[0] * W for _ in range(H)]
    num_up = [[0] * W for _ in range(H)]

    for row in range(H):
        for col in range(W):
            if Grid[row][col] == '.':
                num_left[row][col] = 1 if col == 0 else (num_left[row][col - 1] + 1)

    for row in range(H):
        for col in range(W - 1, -1, -1):
            if Grid[row][col] == '.':
                num_right[row][col] = 1 if col == W - 1 else (num_right[row][col + 1] + 1)

    for col in range(W):
        for row in range(H):
            if Grid[row][col] == '.':
                num_up[row][col] = 1 if row == 0 else (num_up[row - 1][col] + 1)

    for col in range(W):
        for row in range(H - 1, -1, -1):
            if Grid[row][col] == '.':
                num_down[row][col] = 1 if row == H - 1 else (num_down[row + 1][col] + 1)

    ans = max(num_left[row][col] + num_right[row][col] + num_up[row][col]
              + num_down[row][col] - 3 for row in range(H) for col in range(W))
    return ans

H, W = [int(i) for i in input().split()]
Grid = [input() for _ in range(H)]
print(d_lamp(H, W, Grid))

Submission status: Time Limit Exceeded

Solution code:
import fractions as fr
import itertools as it
import collections as col
import heapq as hq
import sys
sys.setrecursionlimit(10**9)
readline = sys.stdin.readline
"""
python3 main.py < input.txt
"""

"""
N=int(input())
W=list(map(int, input().split()))
ans=10**100
for T in range(1,N):
        S1=sum(W[:T])
        S2=sum(W[T:])
        ans = min(ans, abs(S1-S2))
print(ans)
"""
"""
P,Q,R=map(int, input().split())
print(min([P+Q, P+R, Q+R]))
"""
"""
MOD=1000000007
N,M=map(int, input().split())
A=set()
for i in range(M):
        A.add(int(input()))

dp=dict()
dp[0]=1
dp[1]=0 if 1 in A else 1
for i in range(2, N+1):
        if i in A: dp[i] = 0
        else:
                m1=0 if (i-1) in A else dp[i-1]
                m2=0 if (i-2) in A else dp[i-2]
                dp[i]=(m1+m2) % MOD
print(dp[N])
"""
def genArr2(h,w): return [0]*(h*w)
def setArr2(A,ij,x): A[ij[0]*W + ij[1]] = x
def getArr2(A,ij): return A[ij[0]*W + ij[1]]
H,W=map(int, readline().split())
S=genArr2(H,W)
for i in range(H):
        s=readline()
        l=list(s)
        for j in range(W):
                setArr2(S,(i,j),l[j])

SWR=genArr2(H,W)
for i in range(H):
        setArr2(SWR, (i, 0), 0 if getArr2(S, (i, 0)) == "#" else 1)
        for j in range(1,W):
                if getArr2(S,( i, j)) == "#": setArr2(SWR, (i, j), 0)
                else: setArr2(SWR, (i, j), getArr2(SWR, (i, j-1)) + 1)
SWL=genArr2(H,W)
for i in range(H):
        setArr2(SWL, (i, W-1), 0 if getArr2(S, (i, W-1)) == "#" else 1)
        for j in range(W-2,-1,-1):
                if getArr2(S,( i, j)) == "#": setArr2(SWL, (i, j), 0)
                else: setArr2(SWL, (i, j), getArr2(SWL, (i, j+1)) + 1)
SHB=genArr2(H,W)
for j in range(W):
        setArr2(SHB, (0, j), 0 if getArr2(S, (0, j)) == "#" else 1)
        for i in range(1,H):
                if getArr2(S,( i, j)) == "#": setArr2(SHB, (i, j), 0)
                else: setArr2(SHB, (i, j), getArr2(SHB, (i-1, j)) + 1)
SHT=genArr2(H,W)
for j in range(W):
        setArr2(SHT, (H-1, j), 0 if getArr2(S, (H-1, j)) == "#" else 1)
        for i in range(H-2, -1, -1):
                if getArr2(S,( i, j)) == "#": setArr2(SHT, (i, j), 0)
                else: setArr2(SHT, (i, j), getArr2(SHT, (i+1, j)) + 1)

ans=0
for n in range(H*W):
        ij=(n//W,n%W)
        x=getArr2(SWR, ij) + getArr2(SWL, ij) + getArr2(SHB, ij) + getArr2(SHT,ij) - 3
        ans=max(ans,x)
print(ans)

Submission status: Time Limit Exceeded

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

cnt = [[0 for _ in range(W)] for _ in range(H)]
for i in range(H):
  done = [0 for _ in range(W)]
  for j in range(W):
    if S[i][j] == "#":
      continue
    if done[j]:
      continue
    l = 0
    while j + l < W:
      if S[i][j + l] == "#":
        break
      l += 1
    for k in range(l):
      cnt[i][j + k] += l
      done[j + k] = 1

for j in range(W):
  done = [0 for _ in range(H)]
  for i in range(H):
    if S[i][j] == "#":
      continue
    if done[i]:
      continue
    l = 0
    while i + l < H:
      if S[i + l][j] == "#":
        break
      l += 1
    for k in range(l):
      cnt[i + k][j] += l
      done[i + k] = 1

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

Submission status: Time Limit Exceeded

Solution code:
h,w=(int(i) for i in input().split())
a=[]
b=[0 for i in range(w)]
q=0
v=[[] for i in range(w)]
for i in range(h):
  s=input()
  r=[]
  c=0
  for j in range(w):
    if s[j]==".":
      c=c+1
      b[j]=b[j]+1
      if j==w-1:
        for k in range(c):
          r.append(c)
      if i==h-1:
        for k in range(b[j]):
          v[j].append(b[j])
    else:
      for k in range(c):
        r.append(c)
      for k in range(b[j]):
          v[j].append(b[j])
      r.append(0)
      v[j].append(0)
      c=0
      b[j]=0
  a.append(r)
for i in range(h):
  for j in range(w):
    if a[i][j]+v[j][i]-1>q:
      q=a[i][j]+v[j][i]-1
print(q)

Submission status: Time Limit Exceeded

Solution code:
import sys

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

glid = []

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

cost = [[[-1 for y in range(0, h)] for x in range(0, w)] for t in range(0, 4)]
for x in range(0, w):
    for y in range(0, h):
        if glid[y][x] == "#":
            cost[0][x][y] = 0
        elif y >= 1:
            cost[0][x][y] = cost[0][x][y - 1] + 1
        else:
            cost[0][x][y] = 1

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

for y in range(0, h):
    for x in range(0, w):
        if glid[y][x] == "#":
            cost[2][x][y] = 0
        elif x >= 1:
            cost[2][x][y] = cost[2][x - 1][y] + 1
        else:
            cost[2][x][y] = 1

for y in range(0, h):
    for x in range(w - 1, -1, -1):
        if glid[y][x] == "#":
            cost[3][x][y] = 0
        elif x + 1 < w:
            cost[3][x][y] = cost[3][x + 1][y] + 1
        else:
            cost[3][x][y] = 1

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


ans = 0
for x in range(0, w):
    for y in range(0, h):
        sum = 0
        for i in range(0, 4):
            sum += cost[i][x][y]
        ans = max(ans, sum - 3)

print(ans)

Submission status: Time Limit Exceeded

Solution code:

import copy

h, w = map(int , input().split() )

board = [input() for _ in range(h)]

left = [ [0]*w for _ in range(h)] 
right = copy.deepcopy(left )        #いくつ右のマスを照らせるか
down = copy.deepcopy(left)
up = copy.deepcopy(left)



for hi in range(h):
    for wi in range(w):

        if board[hi][wi] == '.':
            left[hi][wi] = 1
            up[hi][wi] = 1

            if 1 <= wi:
                left[hi][wi] += left[hi][wi-1]

            if 1 <= hi:
                up[hi][wi] += up[hi-1][wi]


        if board[hi][w-wi-1] =='.':
            right[hi][w-wi-1] = 1

            if 1<=wi:
                right[hi][w-wi-1] += right[hi][w-wi] 

        if board[h-hi-1][wi] == '.':
            down[h-hi-1][wi] = 1

            if 1 <= hi:
                down[h-hi-1][wi] += down[h-hi][wi]


#def dbcheck():
#    print()
#    tag = ["r","l","d","u"]
#    for t,x in zip(tag,[right,left,down,up]):
#        print(t)
#        for row in x:
#            print(row)
#        print()


#dbcheck()

ans = 0
for i in range(h):
    for j in range(w):
        t = right[i][j]
        t += left[i][j]
        t += up  [i][j]
        t += down[i][j]
        t -= 3
        ans = max(ans,t)

print(ans)

Submission status: Time Limit Exceeded

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

T1=[]
for i in range(H):
    s=S[i]
    t2=s[0]
    if t2==1:
        t1=1
    else:
        t1=0
    t=[]
    k=0
    for j in range(1,W):
        if s[j]==t2:
            if t2==1:
                t1+=1
        else:
            t2=s[j]
            t+=[t1]*(j-k)
            k=j
            if t2==1:
                t1=1
            else:
                t1=0
    else:
        t+=[t1]*(W-k)
    T1+=[t]
T1=np.array(T1)


T2=[]
for i in range(W):
    s=S.T[i]
    t2=s[0]
    if t2==1:
        t1=1
    else:
        t1=0
    t=[]
    k=0
    for j in range(1,H):
        if s[j]==t2:
            if t2==1:
                t1+=1
        else:
            t2=s[j]
            t+=[t1]*(j-k)
            k=j
            if t2==1:
                t1=1
            else:
                t1=0
    else:
        t+=[t1]*(H-k)
    T2+=[t]
T2=np.array(T2).T

print(np.max(T1+T2)-1)

Submission status: Time Limit Exceeded

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

L = [[0 for i in range(W)] for j in range(H)]
R = [[0 for i in range(W)] for j in range(H)]
U = [[0 for i in range(W)] for j in range(H)]
D = [[0 for i in range(W)] for j in range(H)]

ans=0

for i in range(H):
    for j in range(W):
        if S[i][j]=='.':
            if j==0:
                L[i][j]=1
            else:
                L[i][j]=L[i][j-1]+1
        if S[i][-j-1]=='.':
            if j==0:
                R[i][-j-1]=1
            else:
                R[i][-j-1]=R[i][-j]+1
        if S[i][j]=='.':
            if i==0:
                U[i][j]=1
            else:
                U[i][j]=U[i-1][j]+1
        if S[-i-1][j]=='.':
            if i==0:
                D[-i-1][j]=1
            else:
                D[-i-1][j]=D[-i][j]+1
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)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np


def set_values(marr, harr):
    for i in range(len(harr)):
        value = 0
        for j in range(len(harr[i])):
            if marr[i][j]:
                value += 1
                harr[i][j] = value
            else:
                value = 0

    for i in range(len(harr)):
        for j in range(len(harr[i]) - 2, -1, -1):
            if marr[i][j]:
                harr[i][j] = max(harr[i][j], harr[i][j+1])


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

    for i in range(h):
        line = str(input())
        marr.append([True] * w)
        harr.append([0] * w)
        varr.append([0] * w)

        for j in range(w):
            if line[j] == '#':
                marr[i][j] = False

    marr = np.array(marr)
    harr = np.array(harr)
    varr = np.array(varr)
    set_values(marr, harr)

    t_marr = marr.transpose()
    t_varr = varr.transpose()
    set_values(t_marr, t_varr)
    varr = t_varr.transpose()

    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:

import copy

h, w = map(int , input().split() )

board = [input() for _ in range(h)]

left = [ [0]*w for _ in range(h)] 
right = copy.deepcopy(left )        #いくつ右のマスを照らせるか
down = copy.deepcopy(left)
up = copy.deepcopy(left)



for hi in range(h):
    for wi in range(w):

        if board[hi][wi] == '.':
            left[hi][wi] = 1
            up[hi][wi] = 1

            if 1 <= wi:
                left[hi][wi] += left[hi][wi-1]

            if 1 <= hi:
                up[hi][wi] += up[hi-1][wi]


        if board[hi][w-wi-1] =='.':
            right[hi][w-wi-1] = 1

            if 1<=wi:
                right[hi][w-wi-1] += right[hi][w-wi] 

        if board[h-hi-1][wi] == '.':
            down[h-hi-1][wi] = 1

            if 1 <= hi:
                down[h-hi-1][wi] += down[h-hi][wi]


def dbcheck():
    print()
    tag = ["r","l","d","u"]
    for t,x in zip(tag,[right,left,down,up]):
        print(t)
        for row in x:
            print(row)
        print()


#dbcheck()

ans = 0
for i in range(h):
    for j in range(w):
        t = right[i][j]
        t += left[i][j]
        t += up  [i][j]
        t += down[i][j]
        t -= 3
        ans = max(ans,t)

print(ans)

Submission status: Time Limit Exceeded

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

Hor = [0]*H
y = 0
while y != H:
    Hor[y] = []
    i = 0
    while i != W:
        if S[y][i] == ".":
            n = 0
            while i < W and S[y][i] == '.':
                i += 1
                n += 1
            ___ = 0
            while ___ < n:
                Hor[y].append(n)
                ___ += 1
        else:
            Hor[y].append(0)
            i += 1
    y += 1

Ver = [0]*W
x = 0
while x != W:
    Ver[x] = []
    i = 0
    while i != H:
        if S[i][x] == ".":
            n = 0
            while i < H and S[i][x] == '.':
                i += 1
                n += 1
            ___ = 0
            while ___ < n:
                Ver[x].append(n)
                ___ += 1
        else:
            Ver[x].append(0)
            i += 1
    x += 1

ans = 1
x = 0
while x != W:
    y = 0
    while y != H:
        h = Hor[y][x]
        if h:
            v = Ver[x][y]
            ans = max(ans,h+v-1)
        y += 1
    x += 1

print(ans)

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 t in range(0, 4)]
for x in range(0, w):
    for y in range(0, h):
        if glid[y][x] == "#":
            cost[0][x][y] = 0
        elif y >= 1:
            cost[0][x][y] = cost[0][x][y - 1] + 1
        else:
            cost[0][x][y] = 1

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

for y in range(0, h):
    for x in range(0, w):
        if glid[y][x] == "#":
            cost[2][x][y] = 0
        elif x >= 1:
            cost[2][x][y] = cost[2][x - 1][y] + 1
        else:
            cost[2][x][y] = 1

for y in range(0, h):
    for x in range(w - 1, -1, -1):
        if glid[y][x] == "#":
            cost[3][x][y] = 0
        elif x + 1 < w:
            cost[3][x][y] = cost[3][x + 1][y] + 1
        else:
            cost[3][x][y] = 1

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


ans = 0
for x in range(0, w):
    for y in range(0, h):
        sum = 0
        for i in range(0, 4):
            sum += cost[i][x][y]
        ans = max(ans, sum - 3)

print(ans)

Submission status: Time Limit Exceeded

Solution code:
H,W=map(int,input().split())
S=[]
for h in range(H):
    Sh=list(input())
    S.append(Sh)
    
L=[]
for h in range(H):
    Lh=[]
    a=0
    for w in range(W):
        if S[h][w]=='.':
            a+=1
        else:
            a=0
        Lh=Lh+[a]
    L.append(Lh)

R=[]
for h in range(H):
    Rh=[]
    a=0
    for w in range(W):
        if S[h][-(1+w)]=='.':
            a+=1
        else:
            a=0
        Rh=[a]+Rh
    R.append(Rh)

U=[]
for w in range(W):
    Uw=[]
    a=0
    for h in range(H):
        if S[h][w]=='.':
            a+=1
        else:
            a=0
        Uw=Uw+[a]
    U.append(Uw)
U=[[U[w][h] for w in range(W)] for h in range(H)]
    
D=[]
for w in range(W):
    Dw=[]
    a=0
    for h in range(H):
        if S[-(1+h)][w]=='.':
            a+=1
        else:
            a=0
        Dw=[a]+Dw
    D.append(Dw)
D=[[D[w][h] for w in range(W)] for h in range(H)]

maxScore=0
for h in range(H):
    for w in range(W):
        score=L[h][w]+R[h][w]+U[h][w]+D[h][w]-3
        if score>maxScore:
            maxScore=score
print(maxScore)

Submission status: Time Limit Exceeded

Solution code:
H,W = (int(i) for i in input().split())
s = [[-1] * (W + 2) for i in range(H+2)]
t = [[-1] * (W + 2) for i in range(H+2)]
 
for i in range(1, H+1):
    SS = input()
    for j in range(W):
        if SS[j] == "#":
            s[i][j+1] = -1
            t[i][j+1] = -1
        else:
            s[i][j+1] = 0
            t[i][j+1] = 0
 
tmp = []
num = 0
for i in range(1, H+1):
    for j in range(1, W+2):
        if s[i][j] == -1 :
            if num != 0:
                for tp in tmp:
                    s[i][tp] = num
                tmp = []
                num =0
        else:
            tmp.append(j)
            num += 1
 
tmp = []
num = 0
for j in range(1, W+1):
    for i in range(1, H+2):
        if t[i][j] == -1 :
            if num != 0:
                for tp in tmp:
                    t[tp][j] = num
                tmp = []
                num =0
        else:
            tmp.append(i)
            num += 1
 
ref = 0
for i in range(H+2):
    for j in range(W+2):
        ref = max(s[i][j] + t[i][j], ref)
 
print(ref-1)

Submission status: Time Limit Exceeded

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

Hor = [0]*H
y = 0
while y != H:
    Hor[y] = []
    i = 0
    while i != W:
        if S[y][i] == ".":
            n = 0
            while i < W and S[y][i] == '.':
                i += 1
                n += 1
            Hor[y] += [n] * n
        else:
            Hor[y] += [0]
            i += 1
    y += 1

Ver = [0]*W
x = 0
while x != W:
    Ver[x] = []
    i = 0
    while i != H:
        if S[i][x] == ".":
            n = 0
            while i < H and S[i][x] == '.':
                i += 1
                n += 1
            Ver[x] += [n] * n
        else:
            Ver[x] += [0]
            i += 1
    x += 1

ans = 1
x = 0
while x != W:
    y = 0
    while y != H:
        h = Hor[y][x]
        if h:
            v = Ver[x][y]
            ans = max(ans,h+v-1)
        y += 1
    x += 1

print(ans)

Submission status: Time Limit Exceeded

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