Problem:


Score : 400 points

Problem Statement

There is a grid with H horizontal rows and W vertical columns, and there are obstacles on some of the squares.

Snuke is going to choose one of the squares not occupied by an obstacle and place a lamp on it.
The lamp placed on the square will emit straight beams of light in four cardinal directions: up, down, left, and right.
In each direction, the beam will continue traveling until it hits a square occupied by an obstacle or it hits the border of the grid. It will light all the squares on the way, including the square on which the lamp is placed, but not the square occupied by an obstacle.

Snuke wants to maximize the number of squares lighted by the lamp.

You are given H strings S_i (1 \leq i \leq H), each of length W. If the j-th character (1 \leq j \leq W) of S_i is #, there is an obstacle on the square at the i-th row from the top and the j-th column from the left; if that character is ., there is no obstacle on that square.

Find the maximum possible number of squares lighted by the lamp.

Constraints

1 \leq H \leq 2,000

1 \leq W \leq 2,000

S_i is a string of length W consisting of # and ..

. occurs at least once in one of the strings S_i (1 \leq i \leq H).

Input

Input is given from Standard Input in the following format:

H W
S_1
:
S_H

Output

Print the maximum possible number of squares lighted by the lamp.

Sample Input 1

4 6
#..#..
.....#
....#.
#.#...

Sample Output 1

8

If Snuke places the lamp on the square at the second row from the top and the second column from the left, it will light the following squares: the first through fifth squares from the left in the second row, and the first through fourth squares from the top in the second column, for a total of eight squares.

Sample Input 2

8 8
..#...#.
....#...
##......
..###..#
...#..#.
##....#.
#...#...
###.#..#

Sample Output 2

13



Sample input:
4 6
#..#..
.....#
....#.
#.#...


Sample output:
8

Submission status: Time Limit Exceeded

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

S = []
for _ in range(H):
    tmp = list(input())
    S.append(tmp)
    
import numpy as np

Gs = np.asarray(S)
Gs_ = np.rot90(Gs, k=1)

def count_light(Gs):
    Gc = []
    for gs in Gs:
        count = 0
        gc = []
        for s in gs:
            if s == '#':
                count = 0
                gc.append(0)
            else:
                count += 1
                gc.append(count)
        Gc.extend([gc])

    Gc = np.asarray(Gc)

    Gn = []
    for gc in Gc:
        count = -1
        gn = []
        for c in reversed(gc):
            if c == 0:
                count = -1
                gn.append(0)
            else:
                if count == -1:
                    count = c
                gn.append(count)
        gn.reverse()
        Gn.extend([gn])

    Gn = np.asarray(Gn)
    return Gn

Gn = count_light(Gs)
Gn_ = count_light(Gs_)
Gn_ = np.rot90(Gn_, k=-1)

Gsum = Gn+Gn_
ans = np.max(Gsum)-1

        
print(ans)

Submission status: Time Limit Exceeded

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

S = []
for _ in range(H):
    tmp = list(input())
    S.append(tmp)
    
    
import numpy as np

Gs = np.asarray(S)
Gs_ = np.rot90(Gs, k=1)

def count_light(Gs):
    Gc = []
    for gs in Gs:
        count = 0
        gc = []
        for s in gs:
            if s == '#':
                count = 0
                gc.append(0)
            else:
                count += 1
                gc.append(count)
        Gc.append(gc)

    Gc = np.asarray(Gc)

    Gn = []
    for gc in Gc:
        count = -1
        gn = []
        for c in reversed(gc):
            if c == 0:
                count = -1
                gn.append(0)
            else:
                if count == -1:
                    count = c
                gn.append(count)
        gn.reverse()
        Gn.append(gn)

    Gn = np.asarray(Gn)
    return Gn

Gn = count_light(Gs)
Gn_ = count_light(Gs_)
Gn_ = np.rot90(Gn_, k=-1)

Gsum = Gn+Gn_
ans = np.max(Gsum)-1

        
print(ans)

Submission status: Time Limit Exceeded

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

S = []
for _ in range(H):
    tmp = list(input())
    S.append(tmp)
    
import numpy as np

Gs = np.asarray(S)
Gs_ = np.rot90(Gs, k=1)

def count_light(Gs):
    Gc = []
    for gs in Gs:
        count = 0
        gc = []
        for s in gs:
            if s == '#':
                count = 0
                gc.append(0)
            else:
                count += 1
                gc.append(count)
        Gc.append(gc)

    Gc = np.asarray(Gc)

    Gn = []
    for gc in Gc:
        count = -1
        gn = []
        for c in gc[::-1]:
            if c == 0:
                count = -1
                gn.append(0)
            else:
                if count == -1:
                    count = c
                gn.append(count)
        Gn.append(gn[::-1])

    Gn = np.asarray(Gn)
    return Gn

Gn = count_light(Gs)
Gn_ = count_light(Gs_)
Gn_ = np.rot90(Gn_, k=-1)

Gsum = Gn+Gn_
ans = np.max(Gsum)-1

        
print(ans)

Submission status: Time Limit Exceeded

Solution code:
if __name__ == '__main__':
    h,w = list(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)]

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

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


    print(result)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
H, W = map(int,input().split())
S = np.array([list(input()) for _ in range(H)])
horizon = np.zeros((H, W))
vertical = np.zeros((H, W))

# まず横方向に走査
for i in range(H):
  j = 0
  while(j < W):
    # 物が置いてあったら一つ隣に移動
    if(S[i][j] == "#"): 
      j += 1
    # 次にものが置いてあるマスまで移動（inc分移動）
    l = 0
    while(j + l < W):
      if(S[i][j + l] == "#"):
        break
      l += 1
    inc = l
    # 今いる場所からincまで埋める
    horizon[i][j:j+inc] = inc
    j += inc
    
# お行儀悪いけど同じことを縦方向にします
for j in range(W):
  i = 0
  while(i < H):
    # 物が置いてあったら一つ隣に移動
    if(S[i][j] == "#"): 
      i += 1
    # 次にものが置いてあるマスまで移動（inc分移動）
    l = 0
    while(i + l < H):
      if(S[i + l][j] == "#"):
        break
      l += 1
    inc = l
    # 今いる場所からincまで埋める
    horizon[i:i+inc, j] += inc
    i += inc
      
total = np.max(horizon) - 1
print(int(total))

Submission status: Time Limit Exceeded

Solution code:
if __name__ == '__main__':
    h,w = list(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)]

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

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


    print(result)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
H, W = map(int,input().split())
S = np.array([list(input()) for _ in range(H)])
horizon = np.zeros((H, W))
vertical = np.zeros((H, W))

# まず横方向に走査
for i in range(H):
  j = 0
  while(j < W):
    # 物が置いてあったら一つ隣に移動
    if(S[i][j] == "#"): 
      j += 1
    # 次にものが置いてあるマスまで移動（inc分移動）
    l = 0
    while(j + l < W):
      if(S[i][j + l] == "#"):
        break
      l += 1
    inc = l
    # 今いる場所からincまで埋める
    horizon[i][j:j+inc] = inc
    j += inc
    
# お行儀悪いけど同じことを縦方向にします
for j in range(W):
  i = 0
  while(i < H):
    # 物が置いてあったら一つ隣に移動
    if(S[i][j] == "#"): 
      i += 1
    # 次にものが置いてあるマスまで移動（inc分移動）
    l = 0
    while(i + l < H):
      if(S[i + l][j] == "#"):
        break
      l += 1
    inc = l
    # 今いる場所からincまで埋める
    for a in range(i, i+inc):
      vertical[a][j] = inc
    i += inc
      
total = np.max(horizon + vertical) - 1
print(max(int(total), 0))

Submission status: Time Limit Exceeded

Solution code:
if __name__ == '__main__':
    h,w = list(map(int, input().split()))
    s = []
    for i in range(h):
        s.append(input())
    
    yoko = [[0 for i in range(w)] for j in range(h)]
    tate = [[0 for i in range(w)] for j in range(h)]

    for i in range(h):
        index = 0
        while(index < w):
            count = 0
            for j in range(index, w):
                if(s[i][j] == "#"):
                    break
                count += 1
            
            if(count == 0):
                yoko[i][index] = 0
                index += 1

            else:
                for j in range(index, index + count):
                    yoko[i][j] = count
                index += count

    for i in range(w):
        index = 0
        while(index < h):
            count = 0
            for j in range(index, h):
                if(s[j][i] == "#"):
                    break
                count += 1
            
            if(count == 0):
                tate[index][i] = 0
                index += 1

            else:
                for j in range(index, index + count):
                    tate[j][i] = count
                index += count

    result = 0

    for i in range(h):
        for j in range(w):
            result = max(result, yoko[i][j] + tate[i][j] - 1)


    print(result)

Submission status: Time Limit Exceeded

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

S = []
for _ in range(H):
    tmp = list(input())
    S.append(tmp)
    
import numpy as np

Gs = np.asarray(S)
Gs_ = np.rot90(Gs, k=1)

def count_light(Gs):
    Gc = []
    for gs in Gs:
        count = 0
        gc = []
        for s in gs:
            if s == '#':
                count = 0
                gc.append(0)
            else:
                count += 1
                gc.append(count)
        Gc.append(gc)

    Gc = np.asarray(Gc)

    Gn = []
    for gc in Gc:
        count = -1
        gn = []
        for c in gc[::-1]:
            if c == 0:
                count = -1
                gn.append(0)
            else:
                if count == -1:
                    count = c
                gn.append(count)
        Gn.append(gn[::-1])

    Gn = np.asarray(Gn)
    return Gn

Gn = count_light(Gs)
Gn_ = count_light(Gs_)
Gn_ = np.rot90(Gn_, k=3)

Gsum = Gn+Gn_
ans = np.max(Gsum)-1

        
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
H, W = map(int,input().split())
S = np.array([list(input()) for _ in range(H)])
horizon = np.zeros((H, W))
vertical = np.zeros((H, W))

# まず横方向に走査
for i in range(H):
  j = 0
  while(j < W):
    # 物が置いてあったら一つ隣に移動
    if(S[i][j] == "#"): 
      j += 1
    # 次にものが置いてあるマスまで移動（inc分移動）
    l = 0
    while(j + l < W):
      if(S[i][j + l] == "#"):
        break
      l += 1
    inc = l
    # 今いる場所からincまで埋める
    horizon[i][j:j+inc] = inc
    j += inc
    
# お行儀悪いけど同じことを縦方向にします
for j in range(W):
  i = 0
  while(i < H):
    # 物が置いてあったら一つ隣に移動
    if(S[i][j] == "#"): 
      i += 1
    # 次にものが置いてあるマスまで移動（inc分移動）
    l = 0
    while(i + l < H):
      if(S[i + l][j] == "#"):
        break
      l += 1
    inc = l
    # 今いる場所からincまで埋める
    for a in range(i, i+inc):
      vertical[a][j] = inc
    i += inc
      
total = np.max(horizon + vertical) - 1
print(max(int(total), 0))

Submission status: Time Limit Exceeded

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

S = []
for _ in range(H):
    tmp = list(input())
    S.append(tmp)
    
import numpy as np

Gs = np.asarray(S)
Gs_ = np.rot90(Gs, k=1)

def count_light(Gs):
    Gc = []
    for gs in Gs:
        count = 0
        gc = []
        for s in gs:
            if s == '#':
                count = 0
                gc.append(0)
            else:
                count += 1
                gc.append(count)
        Gc.append(gc)

    Gc = np.asarray(Gc)

    Gn = []
    for gc in Gc:
        count = -1
        gn = []
        for c in gc[::-1]:
            if c == 0:
                count = -1
                gn.append(0)
            else:
                if count == -1:
                    count = c
                gn.append(count)
        Gn.append(gn[::-1])

    Gn = np.asarray(Gn)
    return Gn

Gn = count_light(Gs)
Gn_ = count_light(Gs_)
Gn_ = np.rot90(Gn_, k=3)

ans = 0
for gn, gn_ in zip(Gn, Gn_):
    for n, n_ in zip(gn, gn_):
        ans = max(ans, n+n_-1)
        
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

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

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

horizontals = np.empty((H, W), dtype=int)
for h in range(H):
    cnt = 0
    index = 0
    for w in range(W):
        c = S[h][w]
        if c == ".":
            cnt += 1
        else:
            for i in range(cnt):
                horizontals[h][index+i] = cnt
            horizontals[h][w] = 0
            cnt = 0
            index = w+1

    for i in range(cnt):
        horizontals[h][index+i] = cnt

verticals = np.empty((H, W), dtype=int)
for w in range(W):
    cnt = 0
    index = 0
    for h in range(H):
        c = S[h][w]
        if c == ".":
            cnt += 1
        else:
            for i in range(cnt):
                verticals[index+i][w] = cnt
            verticals[h][w] = 0
            cnt = 0
            index = h+1

    for i in range(cnt):
        verticals[index+i][w] = cnt

""" print(horizontals)
print(verticals)
 """
print(np.max(horizontals + verticals) - 1)

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
"""
D - Lamp
https://atcoder.jp/contests/abc129/tasks/abc129_d

"""
import sys


def solve(H, W, grid):
    res_x = [[0]*W for _ in range(H)]
    x, y = 0, 0
    while y < H:
        while x < W:
            if grid[y][x] == '#':
                x += 1
                continue
            rx = x
            while rx < W and grid[y][rx] != '#':
                rx += 1
            for xx in range(x, rx):
                res_x[y][xx] = rx-x
            x = rx
        x = 0
        y += 1

    res_y = [[0]*W for _ in range(H)]
    x, y = 0, 0
    while x < W:
        while y < H:
            if grid[y][x] == '#':
                y += 1
                continue
            ry = y
            while ry < H and grid[ry][x] != '#':
                ry += 1
            for yy in range(y, ry):

                res_y[yy][x] = ry-y
            y = ry
        y = 0
        x += 1

    ans = 0
    for y in range(H):
        for x in range(W):
            t = res_x[y][x] + res_y[y][x] - 1
            if t > ans:
                ans = t
    return ans


def main(args):
    H, W = map(int, input().split())
    grid = [input() for _ in range(H)]
    ans = solve(H, W, grid)
    print(ans)


if __name__ == '__main__':
    main(sys.argv[1:])

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

H, W = list(map(int, input().split()))
s = [input() for i in range(H)]
count = np.zeros((H, W), dtype='int64')

for i in range(H):
    start = np.zeros(2)
    end = np.zeros(2)
    for j in range(W):
        if s[i][j] == '.':
            end[0] += 1
        else:
            count[i, start[0]:end[0]] += end[0]-start[0]
            end[0] += 1
            start[0] = end[0]
    if s[i][j] == '.':
        count[i, start[0]:end[0]] += end[0]-start[0]

for i in range(W):
    start = np.zeros(2)
    end = np.zeros(2)
    for j in range(H):
        if s[j][i] == '.':
            end[1] += 1
        else:
            count[start[1]:end[1], i] += end[1]-start[1]
            end[1] += 1
            start[1] = end[1]
    if s[j][i] == '.':
        count[start[1]:end[1], i] += end[1]-start[1]
        
print(max(np.max(count)-1, 0))

Submission status: Time Limit Exceeded

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

#left
grid_l=[]
for y in range(h):
    grid_l.append([])
    n=0
    for x_chr in L[y]:
        if x_chr=="#":
            n=0
        else:
            n+=1
        grid_l[y].append(n)
    
#print(grid_l)

grid_r=[]
for y in range(h):
    grid_r.append([])
    n=0
    for x_chr in L[y][::-1]:
        if x_chr=="#":
            n=0
        else:
            n+=1
        grid_r[y].append(n)
    grid_r[y].reverse()
    
#print(grid_r)

grid_u=[]
for y in range(h):
    grid_u.append([])
for x in range(w):
    n=0
    for y in range(h):
        if L[y][x]=="#":
            n=0
        else:
            n+=1
        grid_u[y].append(n)

#print(grid_u)

grid_d=[]
for y in range(h):
    grid_d.append([])
for x in range(w):
    n=0
    for y in range(h):
        if L[h-y-1][x]=="#":
            n=0
        else:
            n+=1
        grid_d[h-y-1].append(n)

#print(grid_d)

def score(x,y):
    sc=grid_l[y][x]+grid_r[y][x]+grid_u[y][x]+grid_d[y][x]
    return sc

grid=[]
res=0
for y in range(h):
    for x in range(w):
        res=max(res,score(x,y))
#print(grid)
print(max(res-3,0))

Submission status: Time Limit Exceeded

Solution code:
H, W = map(int, input().split())
S = [input() for _ in range(H)]
 
 
def f(h, w):
    c = 0
    for hh in range(h, -1, -1):
        if S[hh][w] == '#':
            break
        c += 1
    for hh in range(h, H):
        if S[hh][w] == '#':
            break
        c += 1
    for ww in range(w, -1, -1):
        if S[h][ww] == '#':
            break
        c += 1
    for ww in range(w, W):
        if S[h][ww] == '#':
            break
        c += 1
    return c - 3
 
 
def main():
    ans = 0
    for h in range(H):
        for w in range(W):
            if S[h][w] == '#':
                continue
            ans = max(ans, f(h, w))
    print(ans)
 
 
main()

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin/env python3.4

# abc129_d

class Value:
    def __init__(self, v):
        self.v = v

def main():
    # Input
    h, w = [int(s) for s in input().split()]
    s = [input() for _ in range(h)]
    # Get ans
    yoko = [[Value(0) for _ in range(w)] for _ in range(h)]
    tate = [[Value(0) for _ in range(w)] for _ in range(h)]
    for i in range(h):
        cur = None
        for j in range(w):
            if s[i][j] == '#':
                cur = None
            else:
                if cur == None:
                    cur = Value(1)
                else:
                    cur.v += 1
                yoko[i][j] = cur
    for j in range(w):
        cur = None
        for i in range(h):
            if s[i][j] == '#':
                cur = None
            else:
                if cur == None:
                    cur = Value(1)
                else:
                    cur.v += 1
                tate[i][j] = cur
    def gene_ans():
        for i in range(h):
            for j in range(w):
                if s[i][j] == '.':
                    yield tate[i][j].v + yoko[i][j].v
    ans = max(gene_ans())-1
    # Output
    print(ans)

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

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

#left
grid_l=[]
for y in range(h):
    grid_l.append([])
    n=0
    for x_chr in L[y]:
        if x_chr=="#":
            n=0
        else:
            n+=1
        grid_l[y].append(n)
    
#print(grid_l)

grid_r=[]
for y in range(h):
    grid_r.append([])
    n=0
    for x_chr in L[y][::-1]:
        if x_chr=="#":
            n=0
        else:
            n+=1
        grid_r[y].append(n)
    grid_r[y].reverse()
    
#print(grid_r)

grid_u=[]
for y in range(h):
    grid_u.append([])
for x in range(w):
    n=0
    for y in range(h):
        if L[y][x]=="#":
            n=0
        else:
            n+=1
        grid_u[y].append(n)

#print(grid_u)

grid_d=[]
for y in range(h):
    grid_d.append([])
for x in range(w):
    n=0
    for y in range(h):
        if L[h-y-1][x]=="#":
            n=0
        else:
            n+=1
        grid_d[h-y-1].append(n)

#print(grid_d)

def score(x,y):
    sc=max(grid_l[y][x]+grid_r[y][x]+grid_u[y][x]+grid_d[y][x]-3,0)
    return sc

grid=[]
res=0
for y in range(h):
    for x in range(w):
        res=max(res,score(x,y))
#print(grid)
print(res)

Submission status: Time Limit Exceeded

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

#left
grid_l=[]
for y in range(h):
    grid_l.append([])
    n=0
    for x_chr in L[y]:
        if x_chr=="#":
            n=0
        else:
            n+=1
        grid_l[y].append(n)
    
#print(grid_l)

grid_r=[]
for y in range(h):
    grid_r.append([])
    n=0
    for x_chr in L[y][::-1]:
        if x_chr=="#":
            n=0
        else:
            n+=1
        grid_r[y].append(n)
    grid_r[y].reverse()
    
#print(grid_r)

grid_u=[]
for y in range(h):
    grid_u.append([])
for x in range(w):
    n=0
    for y in range(h):
        if L[y][x]=="#":
            n=0
        else:
            n+=1
        grid_u[y].append(n)

#print(grid_u)

grid_d=[]
for y in range(h):
    grid_d.append([])
for x in range(w):
    n=0
    for y in range(h):
        if L[h-y-1][x]=="#":
            n=0
        else:
            n+=1
        grid_d[h-y-1].append(n)

#print(grid_d)

def score(x,y):
    sc=max(grid_l[y][x]+grid_r[y][x]+grid_u[y][x]+grid_d[y][x]-3,0)
    return sc

grid=[]
res=0
for y in range(h):
    grid.append([])
    for x in range(w):
        grid[y].append(score(x,y))
    max_y=max(grid[y])
    res=max(res,max_y)
#print(grid)
print(res)

Submission status: Time Limit Exceeded

Solution code:
h,w = map(int,input().split())
s = [list(input()) for _ in range(h)]
u = [[0]*w for _ in range(h)]
d = [[0]*w for _ in range(h)]
l = [[0]*w for _ in range(h)]
r = [[0]*w for _ in range(h)]
for i in range(h):
  l[i][0] = int(s[i][0] != "#")
  for j in range(1,w):
    if s[i][j] == "#":
      l[i][j] = 0
    else:
      l[i][j] = l[i][j-1] + 1
  r[i][w-1] = int(s[i][w-1] != "#")
  for j in range(w-2,-1,-1):
    if s[i][j] == "#":
      r[i][j] = 0
    else:
      r[i][j] = r[i][j+1] + 1 
for i in range(w):
  d[0][i] = int(s[0][i] != "#")
  for j in range(1,h):
    if s[j][i] == "#":
      d[j][i] = 0
    else:
      d[j][i] = d[j-1][i] + 1
  u[h-1][i] = int(s[h-1][i] != "#")
  for j in range(h-2,-1,-1):
    if s[j][i] == "#":
      u[j][i] = 0
    else:
      u[j][i] = u[j+1][i] + 1
ans = 0
for i in range(h):
  for j in range(w):
    cur = l[i][j] + r[i][j] + u[i][j] + d[i][j]
    if cur>ans:
      ans = cur
print(ans - 3)

Submission status: Time Limit Exceeded

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

S = [["#"]*(W+2)]+[ "#"+input()+"#" for _ in range(H)]+ [["#"]*(W+2)]
H += 2
W += 2
L = [[0]*(W+2) for _ in range(H+2)]
R = [[0]*(W+2) for _ in range(H+2)]
D = [[0]*(W+2) for _ in range(H+2)]
U = [[0]*(W+2) for _ in range(H+2)]
cnt = 0
for i in range(W):
    d[(0,i)] = 1
    d[(H-1,i)] = 1
for i in range(1,H-1):
    for j in range(W):
        if S[i][j] == "#":
            d[(i,j)] = 1
            cnt = 0
        else:
            d[(i,j)] = 0
            cnt += 1
            R[i][j] = cnt
            
for i in range(1,H-1):
    for j in range(W-1,-1,-1):
        if d[(i,j)] == 1:
            cnt = 0
        else:
            cnt += 1
            L[i][j] = cnt

for j in range(1,W-1):
    for i in range(H):
        if  d[(i,j)] == 1:
            cnt = 0
        else:
            cnt += 1
            D[i][j] = cnt

for j in range(1,W-1):
    for i in range(H-1,-1,-1):
        if d[(i,j)] == 1:
            cnt = 0
        else:
            cnt += 1
            U[i][j] = cnt

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

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
h, w = map(int, input().split())

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

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

for i in range(h):
    for j in range(w):
        if grid[i][j] != '#':
            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):
    index_i = h - i -1
    for j in range(w):
        index_j = w - j - 1
        if grid[index_i][index_j] != '#':
            if j == 0:
                r[index_i][index_j] = 1
            else:
                r[index_i][index_j] = r[index_i][index_j + 1] + 1
            if i == 0:
                d[index_i][index_j] = 1
            else:
                d[index_i][index_j] = d[index_i + 1][index_j] + 1

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

Submission status: Time Limit Exceeded

Solution code:
H, W = map( int, input().split())
S = [["#"]*(W+2)]+[ "#"+input()+"#" for _ in range(H)]+ [["#"]*(W+2)]
H += 2
W += 2
L = [[0]*(W+2) for _ in range(H+2)]
R = [[0]*(W+2) for _ in range(H+2)]
D = [[0]*(W+2) for _ in range(H+2)]
U = [[0]*(W+2) for _ in range(H+2)]
cnt = 0

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

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

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

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

Submission status: Time Limit Exceeded

Solution code:
#D問題
H,W = map(int,input().split())
S = [list(str(input())) for i in range(H)]

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

for h in range(H):
    wlist = [0 for i in range(W)]
    indl = [0]
    for w in range(W):
        if S[h][w] == "#":
            indl.append(0)
        else:
            indl[-1]+=1
            wlist[w] = len(indl)-1
    for w in range(W):
        L[h][w]+=indl[wlist[w]]
        
for w in range(W):
    hlist = [0 for i in range(H)]
    indl = [0]
    for h in range(H):
        if S[h][w] == "#":
            indl.append(0)
        else:
            indl[-1]+=1
            hlist[h] = len(indl)-1
    for h in range(H):
        L[h][w]+=indl[hlist[h]]

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

Submission status: Time Limit Exceeded

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

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

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

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

print(ans)

Submission status: Time Limit Exceeded

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

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

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

for i in range(H):
    for j in reversed(range(W)):
        if s[i][j] == "#":
            R[i][j] = 0
        elif j == W-1:
            R[i][j] = 1
        else:
            R[i][j] = R[i][j+1] + 1

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

for i in reversed(range(H)):
    for j in range(W):
        if s[i][j] == "#":
            D[i][j] = 0
        elif i == H-1:
            D[i][j] = 1
        else:
            D[i][j] = D[i+1][j] + 1

ans = 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 > ans:
            ans = tmp

print(ans)

Submission status: Time Limit Exceeded

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

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

hr_scores = []
vr_scores = []


max_value = 0
for w in range(W):
    cnt = 0
    start_h = 0
    lis = []
    for h in range(H):    
        if grids[h][w] == '.':
            cnt += 1
        else:
            lis += [cnt] * (h - start_h) + [0]
            start_h = h + 1
            cnt = 0
    if cnt:
        lis += [cnt] * (h - start_h + 1)
    vr_scores.append(lis)
vr_scores = [[vr_scores[w][h] for w in range(W)] for h in range(H)]
for h in range(H):
    cnt = 0
    start_w = 0
    lis = []
    for w in range(W):
        if grids[h][w] == '.':
            cnt += 1
        else:
            lis += [cnt] * (w - start_w) + [0]
            if cnt:
                max_value = max(
                    max_value,
                    max(vr_scores[h][start_w: w]) + cnt
                )
            start_w = w + 1
            cnt = 0
    if cnt:
        max_value = max(
            max_value,
            max(vr_scores[h][start_w: w + 1]) + cnt
         )

print(max(max_value - 1, 0))