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:
# -*- coding: utf-8 -*-
"""
Created on Sat Apr 20 20:47:47 2019

@author: Owner
"""

import numpy as np
import sys
import collections
import scipy.misc
import math
from operator import itemgetter
import itertools
import copy
import bisect

#素因数を並べる
def prime_decomposition(n):
  i = 2
  table = []
  while i * i <= n:
    while n % i == 0:
      n /= i
      table.append(int(i))
    i += 1
  if n > 1:
    table.append(int(n))
  return table   
# 桁数を吐く
def digit(i):
    if i > 0:
        return digit(i//10) + [i%10]
    else:
        return []
    
def getNearestValueIndex(list, num):
    """
    概要: リストからある値に最も近い値のインデックスを取得する関数
    @param list: データ配列
    @param num: 対象値
    @return 対象値に最も近い値
    """

    # リスト要素と対象値の差分を計算し最小値のインデックスを取得
    idx = np.abs(np.asarray(list) - num).argmin()
    return idx

def find_index(l, x, default=False):
    if x in l:
        return l.index(x)
    else:
        return default

class UnionFind(object):
    def __init__(self, n=1):
        self.par = [i for i in range(n)]
        self.rank = [0 for _ in range(n)]
        self.size = [1 for _ in range(n)]

    def find(self, x):
        """
        x が属するグループを探索
        """
        if self.par[x] == x:
            return x
        else:
            self.par[x] = self.find(self.par[x])
            return self.par[x]

    def union(self, x, y):
        """
        x と y のグループを結合
        """
        x = self.find(x)
        y = self.find(y)
        if x != y:
            if self.rank[x] < self.rank[y]:
                x, y = y, x
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1
            self.par[y] = x
            self.size[x] += self.size[y]

    def is_same(self, x, y):
        """
        x と y が同じグループか否か
        """
        return self.find(x) == self.find(y)

    def get_size(self, x):
        """
        x が属するグループの要素数
        """
        x = self.find(x)
        return self.size[x]
    

"""
N, X = map(int, input().split())

x = list(map(int, input().split()))

P = [0]*N
Y = [0]*N
for n in range(N):
    P[n], Y[n] = map(int, input().split())

# 多次元配列の宣言（あとでintにすること。）（タプルにすること。）
dp = np.zeros((N+1, 4,4,4))
    
all(nstr.count(c) for c in '753')

# 複数配列を並び替え
ABT = zip(A, B, totAB)
result = 0
# itemgetterには何番目の配列をキーにしたいか渡します
sorted(ABT,key=itemgetter(2))
A, B, totAB = zip(*ABT)
A.sort(reverse=True)

# 2進数のbit判定
(x >> i) & 1

# dp最小化問題
dp = [np.inf]*N
for n in range(N):
    if n == 0:
        dp[n] = 0
    else:
        for k in range(1,K+1):
            if n-k >= 0:
                dp[n] = min(dp[n], dp[n-k] + abs(h[n]-h[n-k]))
            else:
                break
# 累積和
add = 1 # 問題によって決まる
res = 0
sums = [0]*(len(nums)+1)
for i in range(len(nums)):
    sums[i+1] = sums[i] + nums[i]
for i in range(0, len(nums), 2):
    left = i
    right = min(i+add, len(nums))
    tmp = sums[right] - sums[left]
    res = max(tmp, res)

#２分探索
li, ri = bisect.bisect_left(p_ac, l[i]-1), bisect.bisect_right(p_ac, r[i]-1)    

#ソート関数
org_list = [3, 1, 4, 5, 2]
new_list = sorted(org_list)
print(org_list)
print(new_list)
# [3, 1, 4, 5, 2]
# [1, 2, 3, 4, 5]

#Distance Transformation
    for h in range(0,H):
        for w in range(0,W):
            if h == 0 and w == 0:
                pass
            elif h == 0:
                D[H-h-1][W-w-1]= min(D[H-h-1][W-w-1], D[H-h-1][W-w]+1)
            elif w == 0:   
                D[H-h-1][W-w-1]= min(D[H-h-1][W-w-1], D[H-h][W-w-1]+1)
            else:
                D[H-h-1][W-w-1]= min(D[H-h-1][W-w-1], D[H-h][W-w-1]+1, D[H-h-1][W-w]+1, D[H-h][W-w]+2)
            d_max = max(D[H-h-1][W-w-1], d_max)

"""


H, W = list(map(int, input().split()))
# 多次元配列の宣言（あとでintにすること。）（タプルにすること。）
A = [""]*H 
#INF = np.Inf
INF = 2000

#D = np.zeros((H, W))
D = np.zeros((H+1, W+1))
for h in range(H):
    A[h] = input()
    for w in range(W):
        if A[h][w] == '.':
            D[h][w] = 1           

def main(): 
    G = np.zeros((H+1, W+1))
    T = np.zeros((H+1, W+1))
    Y = np.zeros((H+1, W+1)) 
    
    
    for h in range(H):
        cnt = 0
        for w in range(W):
            if D[h][w] == 0:
                cnt = 0
                continue
            else:
                Y[h][w] += cnt
                cnt+=1    
    for h in range(H):
        for w in reversed(range(W)):
            if D[h][w] == 0:
               continue
            else:
               Y[h][w] = max(Y[h][w], Y[h][w+1])                           
            
    for w in range(W):
        cnt = 0
        for h in range(H):
            if D[h][w] == 0:
                cnt = 0
                continue
            else:
                T[h][w] += cnt
                cnt+=1
    for w in range(W):
        for h in reversed(range(H)):
            if D[h][w] == 0:
                continue
            else:
                T[h][w] = max(T[h][w], T[h+1][w])
            
    G = D+Y+T
    res = np.amax(G)
    print(int(res))
                
            
            
                

    
if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Sat Apr 20 20:47:47 2019

@author: Owner
"""

import numpy as np
import sys
import collections
import scipy.misc
import math
from operator import itemgetter
import itertools
import copy
import bisect

#素因数を並べる
def prime_decomposition(n):
  i = 2
  table = []
  while i * i <= n:
    while n % i == 0:
      n /= i
      table.append(int(i))
    i += 1
  if n > 1:
    table.append(int(n))
  return table   
# 桁数を吐く
def digit(i):
    if i > 0:
        return digit(i//10) + [i%10]
    else:
        return []
    
def getNearestValueIndex(list, num):
    """
    概要: リストからある値に最も近い値のインデックスを取得する関数
    @param list: データ配列
    @param num: 対象値
    @return 対象値に最も近い値
    """

    # リスト要素と対象値の差分を計算し最小値のインデックスを取得
    idx = np.abs(np.asarray(list) - num).argmin()
    return idx

def find_index(l, x, default=False):
    if x in l:
        return l.index(x)
    else:
        return default

class UnionFind(object):
    def __init__(self, n=1):
        self.par = [i for i in range(n)]
        self.rank = [0 for _ in range(n)]
        self.size = [1 for _ in range(n)]

    def find(self, x):
        """
        x が属するグループを探索
        """
        if self.par[x] == x:
            return x
        else:
            self.par[x] = self.find(self.par[x])
            return self.par[x]

    def union(self, x, y):
        """
        x と y のグループを結合
        """
        x = self.find(x)
        y = self.find(y)
        if x != y:
            if self.rank[x] < self.rank[y]:
                x, y = y, x
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1
            self.par[y] = x
            self.size[x] += self.size[y]

    def is_same(self, x, y):
        """
        x と y が同じグループか否か
        """
        return self.find(x) == self.find(y)

    def get_size(self, x):
        """
        x が属するグループの要素数
        """
        x = self.find(x)
        return self.size[x]
    

"""
N, X = map(int, input().split())

x = list(map(int, input().split()))

P = [0]*N
Y = [0]*N
for n in range(N):
    P[n], Y[n] = map(int, input().split())

# 多次元配列の宣言（あとでintにすること。）（タプルにすること。）
dp = np.zeros((N+1, 4,4,4))
    
all(nstr.count(c) for c in '753')

# 複数配列を並び替え
ABT = zip(A, B, totAB)
result = 0
# itemgetterには何番目の配列をキーにしたいか渡します
sorted(ABT,key=itemgetter(2))
A, B, totAB = zip(*ABT)
A.sort(reverse=True)

# 2進数のbit判定
(x >> i) & 1

# dp最小化問題
dp = [np.inf]*N
for n in range(N):
    if n == 0:
        dp[n] = 0
    else:
        for k in range(1,K+1):
            if n-k >= 0:
                dp[n] = min(dp[n], dp[n-k] + abs(h[n]-h[n-k]))
            else:
                break
# 累積和
add = 1 # 問題によって決まる
res = 0
sums = [0]*(len(nums)+1)
for i in range(len(nums)):
    sums[i+1] = sums[i] + nums[i]
for i in range(0, len(nums), 2):
    left = i
    right = min(i+add, len(nums))
    tmp = sums[right] - sums[left]
    res = max(tmp, res)

#２分探索
li, ri = bisect.bisect_left(p_ac, l[i]-1), bisect.bisect_right(p_ac, r[i]-1)    

#ソート関数
org_list = [3, 1, 4, 5, 2]
new_list = sorted(org_list)
print(org_list)
print(new_list)
# [3, 1, 4, 5, 2]
# [1, 2, 3, 4, 5]

#Distance Transformation
    for h in range(0,H):
        for w in range(0,W):
            if h == 0 and w == 0:
                pass
            elif h == 0:
                D[H-h-1][W-w-1]= min(D[H-h-1][W-w-1], D[H-h-1][W-w]+1)
            elif w == 0:   
                D[H-h-1][W-w-1]= min(D[H-h-1][W-w-1], D[H-h][W-w-1]+1)
            else:
                D[H-h-1][W-w-1]= min(D[H-h-1][W-w-1], D[H-h][W-w-1]+1, D[H-h-1][W-w]+1, D[H-h][W-w]+2)
            d_max = max(D[H-h-1][W-w-1], d_max)

"""


H, W = list(map(int, input().split()))
# 多次元配列の宣言（あとでintにすること。）（タプルにすること。）
A = [""]*H 
#INF = np.Inf
INF = 2000

#D = np.zeros((H, W))
D = np.zeros((H+1, W+1))
for h in range(H):
    A[h] = input()
    for w in range(W):
        if A[h][w] == '.':
            D[h][w] = 1           

def main(): 
    G = copy.deepcopy(D)
    T = np.zeros((H+1, W+1))
    Y = np.zeros((H+1, W+1)) 
    
    
    for h in range(H):
        cnt = 0
        for w in range(W):
            if G[h][w] == 0:
                cnt = 0
                continue
            else:
                Y[h][w] += cnt
                cnt+=1    
    for h in range(H):
        for w in reversed(range(W)):
            if G[h][w] == 0:
               continue
            else:
               Y[h][w] = max(Y[h][w], Y[h][w+1])                           
            
    for w in range(W):
        cnt = 0
        for h in range(H):
            if G[h][w] == 0:
                cnt = 0
                continue
            else:
                T[h][w] += cnt
                cnt+=1
    for w in range(W):
        for h in reversed(range(H)):
            if G[h][w] == 0:
                continue
            else:
                T[h][w] = max(T[h][w], T[h+1][w])
            
    G = G+Y+T
    res = np.amax(G)
    print(int(res))
                
            
            
                

    
if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
import sys
input=sys.stdin.readline
H,W=map(int,input().split())
L=[]
l=["#" for i in range(W+2)]
L.append(l)
#print(L)
for i in range(H):
    s=list(input().rstrip())
    
    L.append(["#"]+s+["#"])
L.append(s)
B=[[0 for i in range(W+2)]for j in range(H+2)]
#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
            B[i][j]+=A[i][j][0]
            A[i][j][1]=A[i-1][j][1]+1
            B[i][j]+=A[i][j][1]
ANS=0
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
            B[H+1-i][W+1-j]+=A[H+1-i][W+1-j][2]
            A[H+1-i][W+1-j][3]=A[H+2-i][W+1-j][3]+1
            B[H+1-i][W+1-j]+=A[H+1-i][W+1-j][3]
            if ANS<(B[H+1-i][W+1-j]-3):
                ANS=(B[H+1-i][W+1-j]-3)
#print(A)

print(ANS)

Submission status: Time Limit Exceeded

Solution code:
import sys
input=sys.stdin.readline
H,W=map(int,input().split())
L=[]
l=["#" for i in range(W+2)]
L.append(l)
#print(L)
for i in range(H):
    s=list(input().rstrip())
    s=["#"]+s+["#"]
    L.append(s)
L.append(s)
B=[[0 for i in range(W+2)]for j in range(H+2)]
#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
            B[i][j]+=A[i][j][0]
            A[i][j][1]=A[i-1][j][1]+1
            B[i][j]+=A[i][j][1]
ANS=0
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
            B[H+1-i][W+1-j]+=A[H+1-i][W+1-j][2]
            A[H+1-i][W+1-j][3]=A[H+2-i][W+1-j][3]+1
            B[H+1-i][W+1-j]+=A[H+1-i][W+1-j][3]
            if ANS<(B[H+1-i][W+1-j]-3):
                ANS=(B[H+1-i][W+1-j]-3)
#print(A)

print(ANS)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
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(l)

#print(L)
npL=np.array(L)
#print(npL)
a=[[[0,0,0,0]for i in range(W+2)]for j in range(H+2)]
npN=np.array(a)
#print(npN)
ans=0
cnt=0
for i in range(1,H+1):
    for j in range(1,W+1):
        if npL[i][j]==".":
            npN[i][j][0]=npN[i][j-1][0]+1
            npN[i][j][1]=npN[i-1][j][1]+1
#print(npN)
for i in range(1,H+1):
    for j in range(1,W+1):
        if npL[H+1-i][W+1-j]==".":
            npN[H+1-i][W+1-j][2]=npN[H+1-i][W+2-j][2]+1
            npN[H+1-i][W+1-j][3]=npN[H+2-i][W+1-j][3]+1
            for k in range(4):
                cnt+=npN[H+1-i][W+1-j][k]
            if (cnt-3)>ans:
                ans=(cnt-3)
            cnt=0
print(ans)
#print(npN)

Submission status: Time Limit Exceeded

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

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

s_lst=[]
for i in range(h):
    s_lst.append(input())
    
matrix_i=[]
for s in s_lst:
    row=[]
    for l in s.split("#"):
        num=len(l)
        for i in range(0,num):
            if num != 0:
                row.append(num)
        row.append(0)
    row.pop(-1)
    matrix_i.append(row)

s_matrix=[]

for s in s_lst:
    s_matrix.append(list(s))
s_lst=[]
for j in range(w):
    s=""
    for i in range(h):
        s+=s_matrix[i][j]
    s_lst.append(s)
matrix_j=[]
for s in s_lst:
    row=[]
    for l in s.split("#"):
        num=len(l)
        for i in range(0,num):
            if num != 0:
                row.append(num)
        row.append(0)
    row.pop(-1)
    matrix_j.append(row)
    
_i=np.array(matrix_i)
_j=np.array(matrix_j)

print(np.max(_i+_j.T)-1)

Submission status: Time Limit Exceeded

Solution code:
import sys

from collections import deque
# q = deque(); q.append(x); q.appendleft(x); q.pop() -> x; q.popleft() -> x
from collections import defaultdict
# d = defaultdict(lambda: []); d[key] -> []
import heapq
# hq = []; heapq.heappush(hq, x); heapq.heappop(hq) -> x; heapq.heappushpop(hq, x) -> x
import bisect
# i = bisect.bisect_left([1,2,3,4], 1.5); i = bisect.bisect_right([4,3,2,1], 1.5)

#import numpy as np
#from scipy.misc import comb

s2nn = lambda s: [int(c) for c in s.split(' ')]
ss2nn = lambda ss: [int(s) for s in ss]
ss2nnn = lambda ss: [s2nn(s) for s in ss]
i2s = lambda: sys.stdin.readline().rstrip()
i2n = lambda: int(i2s())
i2nn = lambda: s2nn(i2s())
ii2ss = lambda n: [sys.stdin.readline().rstrip() for _ in range(n)]
ii2nn = lambda n: ss2nn(ii2ss(n))
ii2nnn = lambda n: ss2nnn(ii2ss(n))

def main():
    H, W = i2nn()
    SS = ii2ss(H)
    D = [[0] * W for _ in range(H)]
    for i in range(H):
        c = 0
        j0 = 0
        for j in range(W):
            s = SS[i][j]
            if s == '.':
                c += 1
            else:
                for k in range(j0, j):
                    D[i][k] += c
                c = 0
                j0 = j + 1
        for k in range(j0, W):
            D[i][k] += c
    #print(D)
    for j in range(W):
        c = 0
        i0 = 0
        for i in range(H):
            s = SS[i][j]
            if s == '.':
                c += 1
            else:
                for k in range(i0, i):
                    D[k][j] += c
                c = 0
                i0 = i + 1
        for k in range(i0, H):
            D[k][j] += c
    #print(D)
    n = 0
    for d in D:
        t = max(d)
        if t > n:
            n = t
    print(n-1)

main()

Submission status: Time Limit Exceeded

Solution code:
H,W = map(int, input().split())
S = [0]*H
for i in range(H):
    S[i] = str(input())
X = [[0 for i in range(H)] for j in range(W)]
for i in range(H):
    s = list(map(str,S[i]))
    for j in range(W):
        if s[j] == ".":
            X[j][i] = 1
        else:
            X[j][i] = 0
M = 1
for i in range(H):
    for j in range(W):
        k = 0
        dx = -1
        dy = -1
        M1 = 1
        if X[j][i] == 1:
            while j + dx >= 0 and X[j + dx +1][i] == 1:
                if X[j + dx][i] == 1:
                    M1 += 1
                dx -= 1
            dx = 1
            while j + dx <W and X[j + dx - 1][i] == 1:
                if X[j + dx][i] == 1:
                    M1 += 1
                dx += 1
                
            while i + dy >= 0 and X[j][i + dy +1] == 1:
                if X[j ][i + dy] == 1:
                    M1 += 1
                dy -= 1
            dy = 1
            while i + dy <H  and X[j][i + dy -1] == 1:
                if X[j ][i + dy] == 1:
                    M1 += 1
                dy += 1
        if M1 > M:
            M = M1
print(M)

Submission status: Time Limit Exceeded

Solution code:

h,w=map(int,input().split())
x1=list(input())
x=[x1]
for u in range(1,h):
	aaa=list(input())
	x.append(aaa)

l=[[0 for _ in range(w)]for _ in range(h)]
r=[[0 for _ in range(w)]for _ in range(h)]
p=[[0 for _ in range(w)]for _ in range(h)]
n=[[0 for _ in range(w)]for _ in range(h)]
count=0
num=0




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

		if(i==0):
			#p[i][j]=0
			pass
		elif (x[i][j]=='#'):
			#p[i][j]=0
			pass
		elif(x[i-1][j]=='#'):
			#p[i][j]=0
			pass
		else:
			p[i][j]=p[i-1][j]+1
		
		
		if(j==0):
			#r[h-1-i][w-1-j]=0
			pass
		elif(x[h-1-i][w-j-1]=='#'):
			#r[h-1-i][w-1-j]=0
			pass
		elif(x[h-1-i][w-j]=='#'):
			#r[h-1-i][w-1-j]=0
			pass
		else:
			r[h-1-i][w-1-j]=r[h-1-i][w-j]+1
		
		
		if(i==0):
			#n[h-1-i][w-1-j]=0
			pass
		elif(x[h-1-i][w-j-1]=='#'):
			#n[h-1-i][w-1-j]=0
			pass
		elif(x[h-i][w-1-j]=='#'):
			#n[h-1-i][w-1-j]=0
			pass
		else:
			n[h-1-i][w-1-j]=n[h-i][w-1-j]+1
			


for a in range(h):
	for b in range(w):
		num=l[a][b]+r[a][b]+p[a][b]+n[a][b]+1
	
		if(count<num):
			count=num
		else:
			pass

print(count)

Submission status: Time Limit Exceeded

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

a = []
for i in range(h):
    a.append(input())

left = [w*[-1] for _ in range(h)]
right = [(w+1)*[w] for _ in range(h)]
up = [w*[-1] for _ in range(h)]
down = [w*[h] for _ in range(h+1)]

for i in range(h):
    for j in range(w):
        up[i][j] = up[i-1][j] if a[i][j] == '.' else i
        left[i][j] = left[i][j-1] if a[i][j] == '.' else j

for i in range(h-1, -1, -1):
    for j in range(w-1, -1, -1):
        down[i][j] = down[i+1][j] if a[i][j] == '.' else i
        right[i][j] = right[i][j+1] if a[i][j] == '.' else j

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

print(ans)

Submission status: Time Limit Exceeded

Solution code:
h,w=map(int,input().split())
x1=list(input())
x=[x1]
for u in range(1,h):
	aaa=list(input())
	x.append(aaa)

l=[[0 for _ in range(w)]for _ in range(h)]
r=[[0 for _ in range(w)]for _ in range(h)]
p=[[0 for _ in range(w)]for _ in range(h)]
n=[[0 for _ in range(w)]for _ in range(h)]
count=0
num=0




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

		if(i==0):
			p[i][j]=0
		elif (x[i][j]=='#'):
			p[i][j]=0
		elif(x[i-1][j]=='#'):
			p[i][j]=0
		else:
			p[i][j]=p[i-1][j]+1

		
		if(j==0):
			r[h-1-i][w-1-j]=0
		elif(x[h-1-i][w-j-1]=='#'):
			r[h-1-i][w-1-j]=0
		elif(x[h-1-i][w-j]=='#'):
			r[h-1-i][w-1-j]=0
		else:
			r[h-1-i][w-1-j]=r[h-1-i][w-j]+1

		
		if(i==0):
			n[h-1-i][w-1-j]=0
		elif(x[h-1-i][w-j-1]=='#'):
			n[h-1-i][w-1-j]=0
		elif(x[h-i][w-1-j]=='#'):
			n[h-1-i][w-1-j]=0
		else:
			n[h-1-i][w-1-j]=n[h-i][w-1-j]+1
		

for a in range(h):
	for b in range(w):
		num=l[a][b]+r[a][b]+p[a][b]+n[a][b]+1

	
		if(count<num):
			count=num
		else:
			pass
		

print(count)

Submission status: Time Limit Exceeded

Solution code:
### 解説読んでから書いたコード ###

h, w = map(int, input().split())
s = [list(input()) for i in range(h)]
# for i in range(h):
#     print(''.join(s[i]))

lighted = [[0 for j in range(w)] for i in range(h)]
left = [[0 for j in range(w)] for i in range(h)]
right = [[0 for j in range(w)] for i in range(h)]
up = [[0 for j in range(w)] for i in range(h)]
down = [[0 for j in range(w)] for i in range(h)]
max_lighted = 0

for i in range(h)[::-1]:
    for j in range(w)[::-1]:
        if s[i][j] != '#':
            right[i][j] = 1 if j == w-1 else right[i][j+1] + 1
            down[i][j] = 1 if i == h-1 else down[i+1][j] + 1

for i in range(h):
    for j in range(w):
        if s[i][j] != '#':
            left[i][j] = 1 if j == 0 else left[i][j-1] + 1
            up[i][j] = 1 if i == 0 else up[i-1][j] + 1
            lighted[i][j] = left[i][j] + right[i][j] + up[i][j] + down[i][j] - 3
            max_lighted = max(max_lighted, lighted[i][j])

print(max_lighted)

# def printcell(dt,h):
#     for i in range(h):
#         print(dt[i])
#     print()

# def printcellstr(dt,h):
#     for i in range(h):
#         print("".join(dt[i]))
#     print()

# printcellstr(s,h)
# printcell(left,h)
# printcell(right,h)
# printcell(up,h)
# printcell(down,h)
# printcell(lighted,h)

Submission status: Time Limit Exceeded

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

l, r, d, u = [[[0 for _ in range(W)] for _ in range(H)] for _ in range(4)]

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

max_num = 0
for y in range(H):
    for x in range(W):
        m = l[y][x] + r[y][x] + u[y][x] + d[y][x] + 1
        # if m > max_num:
        #     print(x, y, l[y][x], r[y][x], u[y][x], d[y][x], m)
        max_num = max(max_num, m)

print(max_num)

Submission status: Time Limit Exceeded

Solution code:
import sys
def solve():
    readline = sys.stdin.readline

    H, W = map(int, readline().split())
    rW = range(W); rH = range(H)
    S = [readline() for i in rH]

    def gen():
        U = [-1]*W
        V = [0]*W
        for i in rH:
            p = -1
            Si = S[i]
            for j in rW:
                if Si[j] == '#':
                    c = j - p - 1
                    for k in range(p+1, j):
                        V[k] = max(V[k], c)
                    yield V[j] + (i - U[j] - 1)
                    V[j] = 0
                    U[j] = i
                    p = j
            c = W - p - 1
            for k in range(p+1, W):
                V[k] = max(V[k], c)
        for u, v in zip(U, V):
            yield v + (H - u - 1)
    sys.stdout.write("%d\n" % (max(gen()) - 1))
solve()

Submission status: Time Limit Exceeded

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

H, W = map(int, readline().split())
rW = range(W); rH = range(H)
S = [readline() for i in rH]
P = [[0]*W for i in rH]
for i in rH:
    p = -1
    Si = S[i]
    Pi = P[i]
    for j in rW:
        if Si[j] == '#':
            c = j - p - 1
            Pi[p+1:j] = (c for k in range(c))
            p = j
    c = W - p - 1
    Pi[p+1:W] = (c for k in range(c))

ans = 0
U = [-1]*W
V = [0]*W
for i in rH:
    Si = S[i]
    for j in rW:
        if Si[j] == '#':
            ans = max(ans, V[j] + (i - U[j] - 1))
            V[j] = 0
            U[j] = i
        else:
            V[j] = max(V[j], P[i][j])
for j in rW:
    ans = max(ans, V[j] + (H - U[j] - 1))
sys.stdout.write("%d\n" % (ans - 1))

Submission status: Time Limit Exceeded

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

H, W = map(int, readline().split())
rW = range(W); rH = range(H)
S = [readline() for i in rH]
P = [[0]*W for i in rH]
for i in rH:
    p = -1
    Si = S[i]
    Pi = P[i]
    for j in rW:
        if Si[j] == '#':
            c = j - p - 1
            Pi[p+1:j] = (c for k in range(c))
            p = j
    c = W - p - 1
    Pi[p+1:W] = (c for k in range(c))
ans = 0
for j in rW:
    p = -1
    v = 0
    for i in rH:
        if S[i][j] == '#':
            ans = max(ans, v + (i - p - 1))
            v = 0
            p = i
        else:
            v = max(v, P[i][j])
    ans = max(ans, v + (H - p - 1))
sys.stdout.write("%d\n" % (ans - 1))

Submission status: Time Limit Exceeded

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

H, W = map(int, readline().split())
S = [readline() for i in range(H)]
P = [[0]*W for i in range(H)]
rW = range(W); rH = range(H)
for i in rH:
    p = -1
    Si = S[i]
    Pi = P[i]
    for j in rW:
        if Si[j] == '#':
            c = j - p - 1
            Pi[p+1:j] = (c for k in range(c))
            p = j
    c = W - p - 1
    Pi[p+1:W] = (c for k in range(c))
for j in rW:
    p = -1
    for i in rH:
        if S[i][j] == '#':
            c = i - p - 1
            for k in range(p+1, i):
                P[k][j] += c
            p = i
    c = H - p - 1
    for k in range(p+1, H):
        P[k][j] += c
ans = 0
for i in range(H):
    for j in range(W):
        if S[i][j] != '#':
            ans = max(ans, P[i][j])
sys.stdout.write("%d\n" % (ans - 1))

Submission status: Time Limit Exceeded

Solution code:
ni = lambda: int(ns())
na = lambda: list(map(int, input().split()))
ns = lambda: input()

h,w  = na()
grid = [input().strip() for i in range(h)]
#print(grid)

T = [[0]*w for i in range(h)]
Y = [[0]*w for i in range(h)]

for i in range(h):
    count=0
    for j in range(w):
        if(grid[i][j]=="#"):
            count=0
        else:
            count+=1
            #print(i,j)
            T[i][j]=count

for i in range(h):
    for j in range(w-2,-1,-1):
        if grid[i][j] == "#":
            T[i][j] = 0
        else:
            T[i][j] = max(T[i][j],T[i][j+1])

for j in range(w):
    count=0
    for i in range(h):
        if(grid[i][j]=="#"):
            count=0
        else:
            count+=1
            Y[i][j]=count

for j in range(w):
    for i in range(h-2,-1,-1):
        if grid[i][j] == "#":
            Y[i][j] = 0
        else:
            Y[i][j] = max(Y[i][j],Y[i+1][j])

ANS = -1
for i in range(h):
    for j in range(w):
        ANS = max(ANS, Y[i][j] + T[i][j] - 1)
#print(T)
#print(Y)
print(ANS)

Submission status: Time Limit Exceeded

Solution code:
H,W=map(int, input().split())
M=[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 M[i][j]=='#':
      L[i][j]=0
      U[i][j]=0
    else:
      if j==0:
        L[i][j]=1
      else:
        L[i][j]=L[i][j-1]+1
        
      if i==0:
        U[i][j]=1
      else:
        U[i][j]=U[i-1][j]+1

    if M[-(i+1)][-(j+1)]=='#':
      R[-(i+1)][-(j+1)]=0
      D[-(i+1)][-(j+1)]=0
    else:
      if j==0:
        R[-(i+1)][-(j+1)]=1
      else:
        R[-(i+1)][-(j+1)]=R[-(i+1)][-(j+1)+1]+1
        
      if i==0:
        D[-(i+1)][-(j+1)]=1
      else:
        D[-(i+1)][-(j+1)]=D[-(i+1)+1][-(j+1)]+1

MAX=0
for i in range(H):
  for j in range(W):
    tmp=L[i][j]+R[i][j]+U[i][j]+D[i][j]-3
    if tmp>MAX:
      MAX=tmp

print(MAX)

Submission status: Time Limit Exceeded

Solution code:
from collections import namedtuple
from itertools import chain

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

def neighbours(n):
    return sum(n)

nodes = []
lastUp = [0] * w
lastLeft = 0
for i in range(h):
    lastLeft = 0
    nodes.append([])
    for j,c in enumerate(input()):
        good = 1 if c == '.' else 0
        left = 0
        up = 0
        right = w - j - 1
        down = h - i - 1
        if good == 1:
            if j > 0:
                l = nodes[i][j - 1]
                left = l[1] + l[0]
            if i > 0:
                u = nodes[i - 1][j]
                up = u[2] + u[0]
        else:
            right = 0
            down = 0
            for k in range(lastLeft, j):
                nodes[i][k][3] = j - k - 1
            for k in range(lastUp[j], i):
                nodes[k][j][4] = i - k - 1
            lastLeft = j + 1
            lastUp[j] = i + 1
        nodes[i].append([good, left, up, right, down])

mx = -1
for i in range(h):
    for j in range(w):
        n = neighbours(nodes[i][j])
        if n > mx:
            mx = n

print(mx)

Submission status: Time Limit Exceeded

Solution code:
H,W=map(int, input().split())
M=[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 M[i][j]=='#':
      L[i][j]=0
      U[i][j]=0
    else:
      if j==0:
        L[i][j]=1
      else:
        L[i][j]=L[i][j-1]+1
        
      if 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-1,-1,-1):
    if M[i][j]=='#':
      R[i][j]=0
      D[i][j]=0
    else:
      if j==W-1:
        R[i][j]=1
      else:
        R[i][j]=R[i][j+1]+1
        
      if i==H-1:
        D[i][j]=1
      else:
        D[i][j]=D[i+1][j]+1

MAX=0
for i in range(H):
  for j in range(W):
    tmp=L[i][j]+R[i][j]+U[i][j]+D[i][j]-3
    if tmp>MAX:
      MAX=tmp

print(MAX)