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:
#!/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 = [[None for _ in range(w)] for _ in range(h)]
    tate = [[None 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
                yoko[i][j] = Value(0)
            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
                tate[i][j] = Value(0)
            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):
                yield tate[i][j].v + yoko[i][j].v - 1
    ans = max(gene_ans())
    # Output
    print(ans)

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:

def main(H, W, s_list):
    row_count = [[0]*W for _ in range(H)]
    for i_row in range(H):
        i_col = 0
        j_col = 0
        s = s_list[i_row]
        while(i_col < W):
            char = s[i_col]
            j_col = i_col
            
            if char == '.':
                while(True):
                    j_col += 1
                    if j_col == W:
                        break
                    c = s[j_col]
                    if c == '#':
                        break
                
                for k in range(i_col, j_col):
                    row_count[i_row][k] = j_col - i_col
            i_col = j_col + 1


    col_count = [[0]*W for _ in range(H)]
    for i_col in range(W):
        i_row = 0
        j_row = 0
        s_col = [s[i_col] for s in s_list]
        while(i_row < H):
            char = s_col[i_row]
            j_row = i_row
            if char == '.':
                while(True):
                    j_row += 1
                    if j_row == H:
                        break
                    c = s_col[j_row]
                    if c == '#':
                        break
                for k in range(i_row, j_row):
                    col_count[k][i_col] = j_row - i_row
            i_row = j_row + 1

    m = 0
    for i_row in range(H):
        for i_col in range(W):
            sumation = row_count[i_row][i_col] + col_count[i_row][i_col]
            if sumation > m:
                m = sumation
    print(int(m) - 1)



if __name__ == "__main__":
    H, W = [int(x) for x in input().split()]
    s_list = []
    for _ in range(H):
        s_list.append(input())

    main(H, W, s_list)

Submission status: Time Limit Exceeded

Solution code:
def makearray(v):
    res = [1]
    if v[0]=="#":
        res = [0]
    for i in v[1:]:
        if i == ".":
            res.append(res[-1]+1)
        else:
            res.append(0)
    return res
        
        

h,w = map(int,input().split())
orimapvert = ['' for _ in range(w)]
orimap = []
L = []
R = []
U = []
D = []
for i in range(h):
    cur = input()
    orimap.append(cur)
    L.append(makearray(cur))
    R.append(list(reversed(makearray("".join(reversed(cur))))))
    for j in range(len(cur)):
        orimapvert[j] += cur[j]
for i in orimapvert:
    U.append(makearray(i))
    D.append(list(reversed(makearray("".join(reversed(i))))))



best = 0
for i in range(h):
    for j in range(w):
        res = L[i][j]+R[i][j]+U[j][i]+D[j][i]-3
        if res > best:
            best = res
print(best)

Submission status: Time Limit Exceeded

Solution code:
H, W = [int(_) for _ in input().split()]
S = []
for _ in range(H):
    S += [1 if _ == '.' else 0 for _ in list(input())]
S += [0] * W
SL = S.copy()
SR = S.copy()
SU = S.copy()
SD = S.copy()
for h in range(H):
    for i in range(W * h + 1, W * (h + 1)):
        if SL[i]:
            SL[i] = SL[i - 1] + 1
        else:
            SL[i] = 0
for h in range(H):
    for i in range(W * h - 2, W * (h - 1) - 1, -1):
        if SR[i]:
            SR[i] = SR[i + 1] + 1
        else:
            SR[i] = 0
for w in range(W):
    for i in range(W + w, W * H + w, W):
        if SU[i]:
            SU[i] = SU[i - W] + 1
        else:
            SU[i] = 0
for w in range(W):
    for i in range(W * (H - 2) + w - 1, -1, -W):
        if SD[i]:
            SD[i] = SD[i + W] + 1
        else:
            SD[i] = 0
score = 0
print(max((SL[_] + SR[_] + SU[_] + SD[_] - 3 for _ in range(H * W))))

Submission status: Time Limit Exceeded

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

A = [[0] * M for i in range(N)]
B = [[0] * M for i in range(N)]
C = [[0] * M for i in range(N)]
D = [[0] * M for i in range(N)]
  
a,b,c,d = 0,0,0,0

for i in range(N):
  a,b = 0,0
  for j in range(M):
    a += 1
    b += 1
    if S[i][j] == '#':
      a = 0
    if S[N - i - 1][M - j - 1] == '#':
      b = 0
    A[i][j] = a
    B[N - i - 1][M - j - 1] = b
    
for j in range(M):
  c,d = 0,0
  for i in range(N):
    c += 1
    d += 1
    if S[i][j] == '#':
      c = 0
    if S[N - i - 1][M - j - 1] == '#':
      d = 0
    C[i][j] = c
    D[N - i - 1][M - j - 1] = d
    
ans = 0
for i in range(N):
  for j in range(M):
    ans = max(ans,A[i][j] + B[i][j] + C[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())

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

hr_scores = np.array([[-1] * W for _ in range(H)])
vr_scores = np.array([[-1] * W for _ in range(H)])

for h in range(H):
    cnt = 0
    start_w = 0
    for w in range(W):
        if grids[h][w] == '.':
            cnt += 1
        else:
            hr_scores[h, w] = 0
            hr_scores[h, start_w: w] = cnt
            start_w = w + 1
            cnt = 0
    if cnt:
        hr_scores[h, start_w: w + 1] = cnt

for w in range(W):
    cnt = 0
    start_h = 0
    for h in range(H):
        if grids[h][w] == '.':
            cnt += 1
        else:
            vr_scores[h, w] = 0
            vr_scores[start_h: h , w] = cnt
            start_h = h + 1
            cnt = 0
    if cnt:
        vr_scores[start_h: h + 1, w] = cnt

print(max((hr_scores + vr_scores).max() - 1, 0))

Submission status: Time Limit Exceeded

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

a = list(range(h))
for i in range(h):
  a[i] = list(map(str,input()))
  a[i].append("#")
  a[i].insert(0,"#")
a.append(["#"]*(w+2))
a.insert(0,(["#"]*(w+2)))

c = 0
c_ = 0
hi = []
wi = []
for i in range(h+2):
  for j in range(w+2):
    if a[i][j] == "#":
      wi.append(c)
      c = 0
    if a[i][j] == ".":
      c += 1
for i in range(w+2):
  for j in range(h+2):    
    if a[j][i] == "#":
      hi.append(c_)
      c_ = 0
    if a[j][i] == ".":
      c_ += 1
print(max(hi)+max(wi)-1)

Submission status: Time Limit Exceeded

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

a = list(range(h))
for i in range(h):
  a[i] = list(map(str,input()))
  a[i].append("#")
  a[i].insert(0,"#")
a.append(["#"]*(w+2))
a.insert(0,(["#"]*(w+2)))

c = 0
c_ = 0
hi = []
wi = []
for i in range(h+2):
  for j in range(w+2):
    if a[i][j] == "#":
      wi.append(c)
      c = 0
    if a[i][j] == ".":
      c += 1
for i in range(w+2):
  for j in range(h+2):    
    if a[j][i] == "#":
      hi.append(c_)
      c_ = 0
    if a[j][i] == ".":
      c_ += 1
print(max(hi)+max(wi)-1)

Submission status: Time Limit Exceeded

Solution code:
# https://atcoder.jp/contests/abc129/tasks/abc129_d

import itertools
from collections import Counter
from collections import defaultdict
import bisect
from heapq import heappush, heappop
import copy

def main():
    H, W = map(int, input().split())
    grid = []
    for _ in range(H):
        w = list(input())
        grid.append(w)

    # w_grid = copy.deepcopy(grid)
    # h_grid = copy.deepcopy(grid)
    w_grid = [[0] * W for _ in range(H)]
    h_grid = [[0] * W for _ in range(H)]

    for h in range(H):
        counter = 0
        for w in range(W):
            if grid[h][w] != '#':
                counter += 1
                w_grid[h][w] = counter
            else:
                counter = 0
                w_grid[h][w] = '#'

    for h in range(H):
        counter = 0
        for w in range(W-1, -1, -1):
            if w_grid[h][w] == '#':
                counter = 0
                continue

            if counter == 0:
                counter = w_grid[h][w]
            else:
                w_grid[h][w] = counter

    for w in range(W):
        counter = 0
        for h in range(H):
            if grid[h][w] != '#':
                counter += 1
                h_grid[h][w] = counter
            else:
                counter = 0
                h_grid[h][w] = '#'

    for w in range(W):
        counter = 0
        for h in range(H-1, -1, -1):
            if h_grid[h][w] == '#':
                counter = 0
                continue

            if counter == 0:
                counter = h_grid[h][w]
            else:
                h_grid[h][w] = counter

    # print(w_grid)
    # print(h_grid)

    # print(w_query)
    def count(i, j):
        h_val = h_grid[i][j]
        w_val = w_grid[i][j]
        val = h_val + w_val
        if h_val > 0 and w_val > 0:
            val -= 1
        return val

    ans = 0
    for h in range(H):
        for w in range(W):
            if grid[h][w] != '#':
                # print('h = {}, w = {}, count = {}'.format(h, w, count(h, w)))
                ans = max(ans, count(h, w))
                pass
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
# https://atcoder.jp/contests/abc129/tasks/abc129_d

import itertools
from collections import Counter
from collections import defaultdict
import bisect
from heapq import heappush, heappop
import copy

def main():
    H, W = map(int, input().split())
    grid = []
    for _ in range(H):
        w = list(input())
        grid.append(w)

    w_grid = copy.deepcopy(grid)
    h_grid = copy.deepcopy(grid)

    for h in range(H):
        counter = 0
        for w in range(W):
            if grid[h][w] != '#':
                counter += 1
                w_grid[h][w] = counter
            else:
                counter = 0

    for h in range(H):
        counter = 0
        for w in range(W-1, -1, -1):
            if w_grid[h][w] == '#':
                counter = 0
                continue

            if counter == 0:
                counter = w_grid[h][w]
            else:
                w_grid[h][w] = counter

    for w in range(W):
        counter = 0
        for h in range(H):
            if grid[h][w] != '#':
                counter += 1
                h_grid[h][w] = counter
            else:
                counter = 0

    for w in range(W):
        counter = 0
        for h in range(H-1, -1, -1):
            if h_grid[h][w] == '#':
                counter = 0
                continue

            if counter == 0:
                counter = h_grid[h][w]
            else:
                h_grid[h][w] = counter

    # print(w_grid)
    # print(h_grid)

    # print(w_query)
    def count(i, j):
        h_val = h_grid[i][j]
        w_val = w_grid[i][j]
        val = h_val + w_val
        if h_val > 0 and w_val > 0:
            val -= 1
        return val

    ans = 0
    for h in range(H):
        for w in range(W):
            if grid[h][w] != '#':
                # print('h = {}, w = {}, count = {}'.format(h, w, count(h, w)))
                ans = max(ans, count(h, w))
                pass
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

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

s = []
for _ in range(h):
    s.append(list(input()))

cnt = [[0] * w for _ in range(h)]

for i in range(h):
    done = [0] * 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] * 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

_max = 0
for i in range(h):
    for j in range(w):
        _max =  max(cnt[i][j] - 1, _max)

print(_max)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

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

# grid[i, j] = 1ならばその位置に障害物がある
grid = np.zeros((h, w), dtype=np.bool)
for i in range(h):
    s = input()
    for j in range(w):
        grid[i, j] = 1 if s[j] == '#' else 0

# 前処理変数
left = np.zeros((h, w), dtype=np.int)
right = np.zeros((h, w), dtype=np.int)
up = np.zeros((h, w), dtype=np.int)
down = np.zeros((h, w), dtype=np.int)

# leftを求める
for i in range(h):
    for j in range(w):
        if grid[i, j]:
            left[i, j] = 0
        elif j == 0:
            left[i, j] = 1
        else:
            left[i, j] = left[i, j-1] + 1

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

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

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

sum = np.zeros((h, w), dtype=np.int)
for i in range(h):
    for j in range(w):
        if grid[i, j]:
            sum[i, j] = 0
        else:
            sum[i, j] = up[i, j] + down[i, j] + left[i, j] + right[i, j] - 3

print(sum.max())

Submission status: Time Limit Exceeded

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

L = [[0 for j in range(W)] for i in range(H)]
R = [[0 for j in range(W)] for i in range(H)]
U = [[0 for j in range(W)] for i in range(H)]
D = [[0 for j in range(W)] for i in range(H)]
for i in range(H):
    for j in range(W):
        L[i][j] = 0 if S[i][j] == '#' else 1 + (0 if j == 0 else L[i][j-1])
    for j in range(W-1, -1, -1):
        R[i][j] = 0 if S[i][j] == '#' else 1 + (0 if j == W-1 else R[i][j+1])
for j in range(W):
    for i in range(H):
        U[i][j] = 0 if S[i][j] == '#' else 1 + (0 if i == 0 else U[i-1][j])
    for i in range(H-1, -1, -1):
        D[i][j] = 0 if S[i][j] == '#' else 1 + (0 if i == H-1 else D[i+1][j])
ans = 0
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 math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,copy,functools

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 10**9 + 7
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(): return [list(map(int, l.split())) for l in sys.stdin.readlines()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)
def pe(s): return print(str(s), file=sys.stderr)
def JA(a, sep): return sep.join(map(str, a))


def main():
    n,m = LI()
    a = [[c!='.' for c in l] for l in sys.stdin.readlines()] + [[True] * m]
    b = [[None] * m for _ in range(n)]
    for i in range(n):
        j = 0
        ai = a[i] + [True]
        bi = b[i]
        while j < m:
            if ai[j]:
                j += 1
            else:
                k = j+1
                while not ai[k]:
                    k += 1
                s = k - j
                bi[j] = s
                if k < m:
                    bi[k] = 0
                j = k

    r = 0
    c = [0] * n
    for j in range(m):
        for i in range(n):
            if b[i][j] is None:
                continue
            c[i] = b[i][j]
        i = 0
        while i < n:
            if a[i][j]:
                i += 1
            else:
                k = i+1
                while not a[k][j]:
                    k += 1
                s = k - i
                t = max(c[i:k]) + s
                if r < t:
                    r = t
                i = k

    return r - 1


print(main())

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
H , W = map(int,input().split())
S = []



hor_obstacle = []
for i in range(H):
	input_word = input()
	temp_obstacle = [-1]
	for j in range(W):
		if input_word[j] == "#":
			temp_obstacle.append(j)
	temp_obstacle.append(W)
	hor_obstacle.append(temp_obstacle)

ver_obstacle = []
for i in range(W):
	temp_obstacle = [-1]
	for j in range(H):
		if i in hor_obstacle[j]:
			temp_obstacle.append(j)
	temp_obstacle.append(H)
	ver_obstacle.append(temp_obstacle)
ans = np.zeros((H,W))

for i in range(H):
	num_1 = 1
	j = 0
	while j < W:
		if j == hor_obstacle[i][num_1]:
			num_1 += 1
		else:
			ans[i][j] += hor_obstacle[i][num_1] - hor_obstacle[i][num_1 - 1] - 1
		j += 1

for i in range(W):
	num_1 = 1
	j = 0
	while j < H:
		if j == ver_obstacle[i][num_1]:
			num_1 += 1
		else:
			ans[j][i] += ver_obstacle[i][num_1] - ver_obstacle[i][num_1 - 1] - 1
		j += 1
print(int(np.max(ans) - 1))

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

def count_dot(s):
    c = []
    for line in s:
        ci = [0 for _ in range(len(line))]
        i2 = 0
        while i2 < len(line):
            i1 = line.find('.', i2)
            if i1 == -1:
                break
            i2 = line.find('#', i1)
            if i2 == -1:
                i2 = len(line)
            for i in range(i1, i2):
                ci[i] = i2 - i1
        c.append(ci)
    return c


def transpose(s):
    return [''.join(i) for i in zip(*s)]


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

s = [input().rstrip() for _ in range(h)]
st = transpose(s)

c1 = np.array(count_dot(s))
c2 = np.array(count_dot(st)).transpose()

c3 = c1 + c2 - 1

print(np.max(c3))

Submission status: Time Limit Exceeded

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

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


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

S = np.array(S)

add_multiply = np.frompyfunc(lambda x, y: (x+y)*y, 2, 1)
h1S = add_multiply.accumulate(S, axis=1, dtype=np.object).astype(int)
h2S = add_multiply.accumulate(
        S[:, ::-1], axis=1, dtype=np.object).astype(int)[:, ::-1]
v1S = add_multiply.accumulate(S, axis=0, dtype=np.object).astype(int)
v2S = add_multiply.accumulate(
        S[::-1, :], axis=0, dtype=np.object).astype(int)[::-1, :]

target = (S != 0)
print((h1S[target] + h2S[target] + v1S[target] + v2S[target] - 3).max())

Submission status: Time Limit Exceeded

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

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


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

S = np.array(S)

add_multiply = np.frompyfunc(lambda x, y: (x+y)*y, 2, 1)
h1S = add_multiply.accumulate(S, axis=1, dtype=np.object).astype(int)
h2S = add_multiply.accumulate(
        S[:, ::-1], axis=1, dtype=np.object).astype(int)[:, ::-1]
v1S = add_multiply.accumulate(S, axis=0, dtype=np.object).astype(int)
v2S = add_multiply.accumulate(
        S[::-1, :], axis=0, dtype=np.object).astype(int)[::-1, :]

print(((h1S + h2S + v1S + v2S - 3)[S != 0]).max())

Submission status: Time Limit Exceeded

Solution code:
import bisect

def main():
    high, width = map(int, input().split())
    data = [list(input()) for i in range(high)]
    ans_list = [[0 for i in range(width)] for j in range(high)]

    for i in range(high):
        for j in range(width):
            if data[i][j] == '.':
                ans_list[i][j] = ans_list[i][j - 1] + 1
        for j in range(width - 1)[::-1]:
            if data[i][j] == '.':
                ans_list[i][j] = max(ans_list[i][j], ans_list[i][j + 1])

    # for i in range(high):
    #     print(ans_list[i])
    # print('---')

    ans_list2 = [[0 for i in range(width)] for j in range(high)]

    for j in range(width):
        for i in range(high):
            if data[i][j] == '.':
                ans_list2[i][j] = ans_list2[i - 1][j] + 1
        for i in range(high - 1)[::-1]:
            if data[i][j] == '.':
                ans_list2[i][j] = max(ans_list2[i][j], ans_list2[i + 1][j])

    ans = 0

    for i in range(high):
        for j in range(width):
            kari = ans_list[i][j] + ans_list2[i][j] - 1
            ans = max(ans, kari)

    print(ans)



if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
H,W=map(int,input().split())
S=[list(input()) for i in range(H)]
Iplus=[[-1 for j in range(W)] for i in range(H)]
Iminus=[[-1 for j in range(W)] for i in range(H)]
Jplus=[[-1 for j in range(W)] for i in range(H)]
Jminus=[[-1 for j in range(W)] for i in range(H)]
for j in range(W):
    if S[0][j]==".":
        Iplus[0][j]=0
for i in range(1,H):
    for j in range(W):
        if S[i][j]==".":
            Iplus[i][j]=Iplus[i-1][j]+1
        else:
            Iplus[i][j]=-1
for j in range(W):
    if S[-1][j]==".":
        Iminus[-1][j]=0
for i in range(H-1)[::-1]:
    for j in range(W):
        if S[i][j]==".":
            Iminus[i][j]=Iminus[i+1][j]+1
        else:
            Iminus[i][j]=-1
for i in range(H):
    if S[i][0]==".":
        Jplus[i][0]=0
for j in range(1,W):
    for i in range(H):
        if S[i][j]==".":
            Jplus[i][j]=Jplus[i][j-1]+1
        else:
            Jplus[i][j]=-1
for i in range(H):
    if S[i][-1]==".":
        Jminus[i][-1]=0
for j in range(W-1)[::-1]:
    for i in range(H):
        if S[i][j]==".":
            Jminus[i][j]=Jminus[i][j+1]+1
        else:
            Jminus[i][j]=-1
ans=0
for i in range(H):
    for j in range(W):
        tmp=Iplus[i][j]+Iminus[i][j]+Jplus[i][j]+Jminus[i][j]+1
        if ans<tmp:
            ans=tmp
            #print(i,j,tmp)
#print(Iplus[2][5],Iminus[2][5],Jplus[2][5],Jminus[2][5])
print(ans)
#for line in Jminus:
#    print(line)

Submission status: Time Limit Exceeded

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

s = [0 for _ in range(h)]

for i in range(0,h):
    s[i] = list(str(input()))

l = [[0 for __ in range(w)] for _ in range(h)]
r = [[0 for __ in range(w)] for _ in range(h)]
d = [[0 for __ in range(w)] for _ in range(h)]
u = [[0 for __ in range(w)] for _ in range(h)]

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

for i in range(h):
    for j in range(w-1,-1,-1):
        if s[i][j] == "#":
            pass
        elif j == w-1:
            r[i][j] = 1
        else:
            r[i][j] = r[i][j+1] + 1

for j in range(w):
    for i in range(h):
        if s[i][j] == "#":
            pass
        elif i == 0:
            u[i][j] = 1
        else:
            u[i][j] = u[i-1][j] + 1

for j in range(w):
    for i in range(h-1,-1,-1):
        if s[i][j] == "#":
            pass
        elif i == h-1:
            d[i][j] = 1
        else:
            d[i][j] = d[i+1][j] + 1

total = [[l[i][j] + r[i][j] + u[i][j] + d[i][j] - 3 for j in range(w)] for i in range(h)]

mm = [max(total[i]) for i in range(h)]

print(max(mm))

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

h, w = list(map(int, input().split()))
d = {".":1, "#":0}
ss = np.array([list(input()) for _ in range(h)])
ss = np.array([[d[x] for x in s] for s in ss])

ls, rs, us, ds = [np.zeros((h, w)) for _ in range(4)]

ls[:, 0] = ss[:, 0]
rs[:, w-1] = ss[:, w-1]
us[0, :] = ss[0, :]
ds[h-1, :] = ss[h-1, :]

for i in range(1, w):
	ls[:, i] = ss[:, i] * (ls[:, i - 1] + 1)

for i in reversed(range(w - 1)):
	rs[:, i] = ss[:, i] * (rs[:, i + 1] + 1)

for i in range(1, h):
	us[i, :] = ss[i, :] * (us[i - 1, :] + 1)

for i in reversed(range(h - 1)):
	ds[i, :] = ss[i, :] * (ds[i + 1, :] + 1)

# print(ss)
# print(ls)
# print(rs)
# print(us)
# print(ds)
print(max(int(np.amax(ls + rs + us + ds) - 3), 0))

Submission status: Time Limit Exceeded

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

s = [0 for _ in range(h)]

for i in range(0,h):
    s[i] = list(str(input()))

l = [[0 for __ in range(w)] for _ in range(h)]
r = [[0 for __ in range(w)] for _ in range(h)]
d = [[0 for __ in range(w)] for _ in range(h)]
u = [[0 for __ in range(w)] for _ in range(h)]

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

for i in range(h):
    for j in range(w-1,-1,-1):
        if s[i][j] == "#":
            pass
        elif j == w-1:
            r[i][j] = 1
        else:
            r[i][j] = r[i][j+1] + 1

for j in range(w):
    for i in range(h):
        if s[i][j] == "#":
            pass
        elif i == 0:
            u[i][j] = 1
        else:
            u[i][j] = u[i-1][j] + 1

for j in range(w):
    for i in range(h-1,-1,-1):
        if s[i][j] == "#":
            pass
        elif i == h-1:
            d[i][j] = 1
        else:
            d[i][j] = d[i+1][j] + 1

total = [[l[i][j] + r[i][j] + u[i][j] + d[i][j] - 3 for j in range(w)] for i in range(h)]

#print(l)
#print(r)
#print(u)
#print(d)
#print(total)
mm = [max(total[i]) for i in range(h)]

print(max(mm))

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

h, w = list(map(int, input().split()))
d = {".":0, "#":1}
ss = np.array([list(input()) for _ in range(h)])
ss = np.array([[d[x] for x in s] for s in ss])

ans = 0
ls = np.zeros((h, w))
rs = np.zeros((h, w))
us = np.zeros((h, w))
ds = np.zeros((h, w))

for i in range(h):
	if ss[i, 0] == 0:
		ls[i, 0] = 1
	for j in range(1, w):
		if ss[i, j] == 0:
			ls[i, j] = ls[i, j - 1] + 1		

	if ss[i, w - 1] == 0:
		rs[i, w - 1] = 1
	for j in reversed(range(w - 1)):
		if ss[i, j] == 0:
			rs[i, j] = rs[i, j + 1] + 1

for j in range(w):
	if ss[0, j] == 0:
		us[0, j] = 1
	for i in range(1, h):
		if ss[i, j] == 0:
			us[i, j] = us[i - 1, j] + 1

	if ss[h - 1, j] == 0:
		ds[h - 1, j] = 1
	for i in reversed(range(h - 1)):
		if ss[i, j] == 0:
			ds[i, j] = ds[i + 1, j] + 1

# print(ss)
# print(ls)
# print(rs)
# print(us)
# print(ds)

print(max(int(np.amax(ls + rs + us + ds) - 3), 0))

Submission status: Time Limit Exceeded

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

h,w = map(int,input().split())
ss = []
for i in range(h):
    ss.append(input())

v = [[0 for _ in range(w)] for _ in range(h)]
lh = [0 for _ in range(w)]
lw = 0

for i in range(0,h):
    lw = 0
    for j in range(w):
        if ss[i][j] == "#":
            i2 = i-1
            while i2 >= 0 and ss[i2][j] == ".":
                 v[i2][j] += lh[j]
                 i2 -= 1
            j2 = j-1
            while j2 >= 0 and ss[i][j2] == ".":
                 v[i][j2] += lw
                 j2 -= 1
            lh[j] = 0
            lw = 0
            continue
        
        lh[j] += 1
        lw += 1

        if i == h-1:
            i2 = i
            while i2 >= 0 and ss[i2][j] == ".":
                 v[i2][j] += lh[j]
                 i2 -= 1

        if j == w-1:
            j2 = j
            while j2 >= 0 and ss[i][j2] == ".":
                 v[i][j2] += lw
                 j2 -= 1

ans = 0
for i in range(h):
    v[i].sort(reverse=True)
    if ans < v[i][0]:
        ans = v[i][0]

print(ans-1)