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: Wrong Answer

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

R = np.zeros((H,W))
L = np.zeros((H,W))
U = np.zeros((H,W))
D = np.zeros((H,W))
for i in range(H):
  for j in range(W):
    if S[i][j] == "#":
      L[i][j] = 0
    else:
      if 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,0,-1):
    if S[i][j] == "#":
      R[i][j] = 0
    else:
      if 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] == "#":
      U[i][j] = 0
    else:
      if 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,0,-1):
    if S[i][j] == "#":
      D[i][j] = 0
    else:
      if 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):
    ans = max(ans, L[i][j]+R[i][j]+U[i][j]+D[i][j]-3)
print (int(ans))

Submission status: Wrong Answer

Solution code:
H, W=map(int, input().split())
S=list(input()+"#" for _ in range(H))
S.append("".join("#" for _ in range(W+1)))
maxrow=0
for r in range(H+1):
  tmp=0
  for c in range(W+1):
    x=S[r][c]
    if x==".":
      tmp+=1
    else:
      maxrow=max(maxrow, tmp)
      tmp=0
maxcolumn=0
for c in range(W+1):
  tmp=0
  for r in range(H+1):
    x=S[r][c]
    if x==".":
      tmp+=1
    else:
      maxcolumn=max(maxcolumn, tmp)
      tmp=0
print(maxrow+maxcolumn-1)

Submission status: Wrong Answer

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

def main():
    H,W = map(int, input().split())
    
    S = []
    for _ in range(H):
        S.append(input().strip()+"#")

    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 y in range(H):
        for x in range(W):
            if S[y][x] == "#":
                u[y][x] = l[y][x] = 0
            else:
                u[y][x] = 1 if y == 0 else u[y-1][x] + 1
                l[y][x] = 1 if x == 0 else l[y][x-1] + 1
            ty = H-1-y
            if S[ty][x] == "#":
                d[y][x] = 0
            else:
                d[ty][x] = 1 if ty == H-1 else d[ty+1][x] + 1
            tx = W-1-x
            if S[y][tx] == "#":
                r[y][x] = 0
            else:
                r[y][tx] = 1 if tx == W-1 else r[y][tx+1] + 1

    ans = 0
    for y in range(H):
        for x in range(W):
            ans = max(ans, u[y][x] + d[y][x] + l[y][x] + r[y][x] - 3)
    print(ans)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
def slove():
    import sys
    input = sys.stdin.readline
    h, w = list(map(int, input().rstrip('\n').split()))
    s = [list(str(input().rstrip('\n'))) for _ in range(h)]

    U = [[0] * w for _ in range(h)]
    D = [[0] * w for _ in range(h)]
    R = [[0] * w for _ in range(h)]
    L = [[0] * w for _ in range(h)]

    for i in range(1):
        for j in range(w):
            U[i][j] = 1 if s[i][j] != "#" else 0
            D[-i-1][j] = 1 if s[-i-1][j] != "#" else 0
    for i in range(h):
        for j in range(1):
            R[i][-j-1] = 1 if s[i][-j-1] != "#" else 0
            L[i][j] = 1 if s[i][j] != "#" else 0

    for i in range(1, h):
        for j in range(1, w):
            U[i][j] = 1 + U[i-1][j] if s[i][j] != "#" else 0
            D[-i-1][j] = 1 + D[-i][j] if s[-i-1][j] != "#" else 0
            R[i][-j-1] = 1 + R[i][-j] if s[i][-j-1] != "#" else 0
            L[i][j] = 1 + L[i][j-1] if s[i][j] != "#" else 0
    mt = 0
    for i in range(h):
        for j in range(w):
            mt = max(mt, U[i][j] + D[i][j] + R[i][j] + L[i][j] - 3)
    print(mt)


if __name__ == '__main__':
    slove()

Submission status: Wrong Answer

Solution code:
h, w = map(int, input().split())
grid = [None]*h
cnt = [[0 for _ in range(w+1)] for __ in range(h+1)]
print(cnt)
for i in range(h):
    grid[i] = list(input())
for i in range(h):
    done = [0]*w
    for j in range(w):
        if grid[i][j] == "#": continue
        if done[j] == 1: continue
        l = 0
        while j+l < w:
            if grid[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 grid[i][j] == "#": continue
        if done[i] == 1: continue
        l = 0
        while i+l < h:
            if grid[i+l][j] == "#": break
            l += 1
        for k in range(l):
            cnt[i+k][j] += l
            done[i+k] = 1
ans = 0
for i in range(h):
    for j in range(w):
        ans = max(ans, cnt[i][j]-1)
print(ans)

Submission status: Wrong Answer

Solution code:
def main():
    import sys
    input = sys.stdin.readline
    H, W = map(int, input().split())
    grid = [0]*H
    A = [[0] * W for i in range(H)]
    for i in range(H):
        grid[i] = [1 if x == '#' else 0 for x in input().rstrip()]

    for i in range(H):
        L = grid[i]
        AL = A[i]
        AL[0] = 0 if L[0] == 1 else 1
        for j in range(1, W):
            if L[j] == 1:
                AL[j] = 0
            else:
                AL[j] = AL[j-1] + 1
        for j in range(W-1)[::-1]:
            if L[j+1] == 1 or L[j] == 1:
                continue
            else:
                AL[j] = AL[j+1]

    V = [[0] * W for i in range(H)]
    m = 0
    for i in range(W):
        V[0][i] = 0 if grid[0][i] == 1 else 1
        for j in range(1, H):
            if grid[j][i] == 1:
                continue
            V[j][i] = V[j-1][i] + 1
        for j in range(H-1)[::-1]:
            if grid[j+1][i] == 1 or grid[j][i] == 1:
                continue
            else:
                V[j][i] = V[j+1][i]
                m = max(m, A[j][i] + V[j][i] - 1)
    print(m)
main()

Submission status: Wrong Answer

Solution code:
h, w = map(int, input().split())
S = [list(input()) for _ in range(h)]
L = [[0] * w for _ in range(h)]
for i in range(h):
    for j in range(w):
        # if S[i][j] == '#':
        #     L[i][j] = 0
        if j == 0:
            L[i][j] = 1
        else:
            L[i][j] = L[i][j-1] + 1
R = [[0] * w for _ in range(h)]
for i in range(h):
    for j in reversed(range(w)):
        # if S[i][j] == '#':
        #     R[i][j] = 0
        if j == w-1:
            R[i][j] = 1
        else:
            R[i][j] = R[i][j+1] + 1
U = [[0] * w for _ in range(h)]
for j in range(w):
    for i in range(h):
        # if S[i][j] == '#':
        #     U[i][j] = 0
        if i == 0:
            U[i][j] = 1
        else:
            U[i][j] = U[i-1][j] + 1
D = [[0] * w for _ in range(h)]
for j in range(w):
    for i in reversed(range(h)):
        # if S[i][j] == '#':
        #     D[i][j] = 0
        if i == h-1:
            D[i][j] = 1
        else:
            D[i][j] = D[i+1][j] + 1
tmp = [[0] * w for _ in range(h)]
for i in range(h):
    for j in range(w):
        tmp[i][j] = L[i][j] + R[i][j] + U[i][j] + D[i][j] - 3
ans = 0
for i in range(h):
    for j in range(w):
        ans = max(ans, tmp[i][j])
print(ans)

Submission status: Wrong Answer

Solution code:
H, W = map(int,input().split())
S = [ str(input()) for i in range(H) ]
yoko = []
for i in range(H):
    tmp = [-1]
    for j in range(W):
        if S[i][j] == '#':
            tmp.append(j)
    tmp.append(W)
    yoko.append(tmp)
yokoval = [0]*(W*H)
for i in range(H):
    tmp = 0
    for j in range(W):
        if S[i][j] == '#':
            tmp += 1
            continue
        yokoval[i*W+j] = yoko[i][tmp+1]-yoko[i][tmp]-1
tate = []
for i in range(W):
    tmp = [-1]
    for j in range(H):
        if S[j][i] == '#':
            tmp.append(j)
    tmp.append(H)
    tate.append(tmp)
tateval = [0]*(W*H)
for i in range(W):
    tmp = 0
    for j in range(H):
        if S[j][i] == '#':
            tmp += 1
            continue
        tateval[i*H+j] = tate[i][tmp+1]-tate[i][tmp]-1
tateval2 = []
for i in range(W):
    for j in range(H):
        tateval2.append(tateval[j*W+i])
sumlist = [yokoval[i]+tateval2[i] for i in range(H*W)]
print(max(sumlist)-1)

Submission status: Wrong Answer

Solution code:
import sys

#+++++

def pp_in():
	s=input()
	return '#'+s+'#'
		
def main():
	h , w = map(int, input().split())
	mm=[pp_in() for _ in range(h)]
	ap='#'*(w+2)
	mm=[ap]+mm
	mm.append(ap)
	
	rr0=[[0]*(w+2) for _ in range(h+2)]
	rr1=[[0]*(w+2) for _ in range(h+2)]
	
	for hi, hm in enumerate(mm):
		start=-1
		for wj, wc in enumerate(hm):
			if wc == '.' and start == -1:
				#it's new '.' pos.
				start=wj
			elif wc == '.':
				pass
			elif wc == '#' and start == -1:
				pass
			else:
				lb = wj - start
				for ii in range(start, wj):
					rr0[hi][ii] = lb
				start=-1
	
	for wi in range(w+2):
		start=-1
		for hj in range(h+2):
			cc=mm[hj][wi]
			if cc == '.' and start == -1:
				#it's new '.' pos.
				start=hj
			elif cc == '.':
				pass
			elif cc == '#' and start == -1:
				pass
			else:
				lb = hj - start
				for ii in range(start, hj):
					rr1[ii][wi] = lb
				start=-1
				
	p_ret=max([max([a+b for a,b in zip(r0,r1)]) for r0,r1 in zip(rr0, rr1)])
	ret=p_ret-1
	return ret

	
#+++++

if __name__ == "__main__":
	if sys.platform =='ios':
		sys.stdin=open('inputFile.txt')
		isTest=True
	else:
		pass
		input = sys.stdin.readline
			
	ret = main()
	if ret is not None:
		print(ret)

Submission status: Wrong Answer

Solution code:
h,w=map(int,input().split())
s=[list(input()) for i in range(h)]
li=[[0,0] for i in range(h*w)]

for i in range(h):
    now=0
    for j in range(w):
        if li[i*w+j][0]!=0:
            continue
        elif s[i][j]=='.':
            now+=1
            if j==w-1:
                for k in range(j+1-now,j+1):
                    li[i*w+k][0]=now
                now=0
        else:
            for k in range(j-now,j):
                li[i*w+k][0]=now
            now=0

for i in range(w):
    now=0
    for j in range(h):
        if li[j*w+i][1]!=0:
            continue
        elif s[j][i]=='.':
            now+=1
            if j==h-1:
                for k in range(j+1-now,j+1):
                    li[k*w+i][1]=now
                now=0
        else:
            for k in range(j-now,j):
                li[k*w+i][1]=now
            now=0
    
ans=0    
for i in range(len(li)):
    ans=max(ans,sum(li[i]))
    
print(ans)

Submission status: Wrong Answer

Solution code:
h,w=map(int,input().split())
s=[list(input()) for i in range(h)]
li=[[0,0] for i in range(h*w)]

for i in range(h):
    now=0
    for j in range(w):
        if li[i*w+j][0]!=0:
            continue
        elif s[i][j]=='.':
            now+=1
            if j==w-1:
                for k in range(j+1-now,j+1):
                    li[i*w+k][0]=now
                now=0
        else:
            for k in range(j-now,j):
                li[i*w+k][0]=now
            now=0

for i in range(w):
    now=0
    for j in range(h):
        if li[j*w+i][1]!=0:
            continue
        elif s[j][i]=='.':
            now+=1
            if j==h-1:
                for k in range(j+1-now,j+1):
                    li[k*w+i][1]=now
                now=0
        else:
            for k in range(j-now,j):
                li[k*w+i][1]=now
            now=0
print(li)   
    
ans=0    
for i in range(len(li)):
    ans=max(ans,sum(li[i]))
    
print(ans)

Submission status: Wrong Answer

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

L = [[1]*W for i in range(H)]
R = [[1]*W for i in range(H)]
U = [[1]*W for i in range(H)]
D = [[1]*W for i in range(H)]
ans = 0
for i in range(H):
    for j in range(W):
        if S[i][j] == "#":
            L[i][j] = 0
            U[i][j] = 0
        elif i == 0 and j == 0:
            continue
        elif i == 0:
            L[i][j] = L[i][j-1] + 1
        elif j == 0:
            U[i][j] = U[i-1][j] + 1
        else:
            L[i][j] = L[i][j-1] + 1
            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 S[i][j] == "#":
            R[i][j] = 0
            D[i][j] = 0
        elif i == H-1 and j == W-1:
            continue
        elif i == H-1:
            R[i][j] = R[i][j+1] + 1
        elif j == W-1:
            D[i][j] = D[i+1][j] + 1
        else:
            R[i][j] = R[i][j+1] + 1
            D[i][j] = D[i+1][j] + 1
        tmp = L[i][j] + R[i][j] + D[i][j] + U[i][j] - 3
        if tmp > ans:
            ans = tmp

print(ans)

Submission status: Wrong Answer

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

x = [] * W
y = [] * H
L = [[1]*W for i in range(H)]
R = [[1]*W for i in range(H)]
U = [[1]*W for i in range(H)]
D = [[1]*W for i in range(H)]
ans = 0
for i in range(H):
    for j in range(W):
        if S[i][j] == "#":
            L[i][j] = 0
            U[i][j] = 0
        elif i == 0 and j == 0:
            continue
        elif i == 0:
            L[i][j] = L[i][j-1] + 1
        elif j == 0:
            U[i][j] = U[i-1][j] + 1
        else:
            L[i][j] = L[i][j-1] + 1
            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 S[i][j] == "#":
            R[i][j] = 0
            D[i][j] = 0
        elif i == H-1 and j == W-1:
            continue
        elif i == H-1:
            R[i][j] = R[i][j+1] + 1
        elif j == W-1:
            D[i][j] = D[i+1][j] + 1
        else:
            R[i][j] = R[i][j+1] + 1
            D[i][j] = D[i+1][j] + 1
        tmp = L[i][j] + R[i][j] + D[i][j] + U[i][j] - 3
        if tmp > ans:
            ans = tmp

print(ans)

Submission status: Wrong Answer

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

s = [input() for i in range(h)]

init = lambda :[[0] * (w+2) for i in range(h+2)]
r, l, u, d = init(), init(), init(), init()

for i in range(1, h+1):
    for j in range(1, w+1):
        if s[i-1][j-1] == ".":
            l[i][j] = l[i][j-1] + 1
            u[i][j] = u[i-1][j] + 1
        else:
            l[i][j] = 0
            u[i][j] = 0

for i in range(h, 0, -1):
    for j in range(w, 0, -1):
        if s[i-1][j-1] == ".":
            r[i][j] = r[i][j+1] + 1
            d[i][j] = d[i+1][j] + 1
        else:
            r[i][j] = 0
            d[i][j] = 0

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

Submission status: Wrong Answer

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

for i in range(H):
    map_list.append(list(input()))



def dfs(x, y):
    countx = 0
    county = 0
    count = 0
    issharp = False
    issharpy = False
    if map_list[x][y] == "#":
        return 0
    else:
        count += 1

    for dx in range(len(map_list[x])):
        if dx != y:
            if map_list[x][dx] == "#":
                if issharp:
                    break
                else:
                    if dx < y:
                        countx = 0
                        issharp = True
            else:
                countx += 1

    for dy in range(H):
        if dy != y:
            if map_list[dy][y] == "#":
                if issharpy:
                    break
                else:
                    if x > dy:
                        county = 0
                        issharpy = True
            else:
                county += 1

    count += (countx + county)

    return count


countlist = []

for i in range(H):
    for u in range(W):
        countlist.append(dfs(i, u))


print(max(countlist))

Submission status: Wrong Answer

Solution code:
h, w = map(int, input().split())
s = [input() for _ in range(h)]
L = [[0] * w for _ in range(h)]
R = [[0] * w for _ in range(h)]
U = [[0] * w for _ in range(h)]
D = [[0] * w for _ in range(h)]
ans = 0
for i in range(h):
    for j in range(w):
        if j != 0:
            L[i][j] = L[i][j - 1]
        if s[i][j] == ".":
            L[i][j] += 1
for i in range(h):
    for j in range(w - 1, -1, -1):
        if j != w - 1:
            R[i][j] = R[i][j + 1]
        if s[i][j] == ".":
            R[i][j] += 1
for j in range(w):
    for i in range(h):
        if i != 0:
            U[i][j] = U[i - 1][j]
        if s[i][j] == ".":
            U[i][j] += 1
for j in range(w):
    for i in range(h - 1, -1, -1):
        if i != h - 1:
            D[i][j] = D[i + 1][j]
        if s[i][j] == ".":
            D[i][j] += 1
for i in range(h):
    for j in range(w):
        if s[i][j] == ".":
            ans = max(ans, L[i][j] + R[i][j] + U[i][j] + D[i][j] - 3)
print(ans)

Submission status: Wrong Answer

Solution code:
h, w = map(int, input().split())
s = [input() for _ in range(h)]
L = [[0] * w for _ in range(h)]
R = [[0] * w for _ in range(h)]
U = [[0] * w for _ in range(h)]
D = [[0] * w for _ in range(h)]
ans = 0
for i in range(h):
    for j in range(w):
        if j != 0:
            L[i][j] = L[i][j - 1]
        if s[i][j] == ".":
            L[i][j] += 1
for i in range(h):
    for j in range(w - 1, -1, -1):
        if j != w - 1:
            R[i][j] = R[i][j + 1]
        if s[i][j] == ".":
            R[i][j] += 1
for j in range(w):
    for i in range(h):
        if i != 0:
            U[i][j] = U[i - 1][j]
        if s[i][j] == ".":
            U[i][j] += 1
for j in range(w):
    for i in range(h - 1, -1, -1):
        if i != h - 1:
            D[i][j] = D[i + 1][j]
        if s[i][j] == ".":
            D[i][j] += 1
for i in range(h):
    for j in range(w):
        ans = max(ans, L[i][j] + R[i][j] + U[i][j] + D[i][j] - 3)
print(ans)

Submission status: Wrong Answer

Solution code:
import numpy as np

h,w = map(int,input().split(" "))
s = [[0 for i in range(w)] for j in range(h)]
for i in range(h):
    tmp = list(input())
    for j in range(w):
        s[i][j] = tmp[j]

dp1 = np.full((2000,2000),-1)
dp2 = np.full((2000,2000),-1)
dp3 = np.full((2000,2000),-1)
dp4 = np.full((2000,2000),-1)



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

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

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

a = 1
for i in range(h):
    for j in range(w):
        if s[i][j] == "#":
            dp1[i][j] = 0
        elif j == 0:
            dp1[i][j] = 1
        else:
            dp1[i][j] = 1 + dp1[i][j-1]
        a = max(a,dp1[i][j]+dp2[i][j]+dp3[i][j]+dp4[i][j]-3)

print(a)

Submission status: Wrong Answer

Solution code:
# ABC129D - Lamp
import sys
input = sys.stdin.readline

def main():
    H, W = tuple(map(int, input().split()))
    S = tuple(input().rstrip() for _ in range(H))
    L, R = [[0] * W for _ in range(H)], [[0] * W for _ in range(H)]
    U, D = [[0] * W for _ in range(H)], [[0] * W for _ in range(H)]
    for x1 in range(H):
        for y1 in range(W):
            if S[x1][y1] == ".":  # left and upper sides of S[i][j]
                U[x1][y1] = U[x1 - 1][y1] + 1
                L[x1][y1] = L[x1][y1 - 1] + 1
            x2, y2 = -x1 - 1, -y1 - 1
            if S[x2][y2] == ".":  # right and under sides
                D[x2][y2] = D[x2 + 1][y2] + 1
                R[x2][y2] = R[x2][y2 + 1] + 1
    ans = -float("inf")
    for i in range(H):
        for j in range(W):
            x = L[i][j] + R[i][j] + U[i][j] + D[i][j] - 3
            if x < ans:
                ans = x
    print(ans)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
# ABC129D - Lamp
import sys
input = sys.stdin.readline

def main():
    H, W = tuple(map(int, input().split()))
    S = tuple(input().rstrip() for _ in range(H))
    L, R = [[0] * (W + 2) for _ in range(H + 2)], [[0] * (W + 2) for _ in range(H + 2)]
    U, D = [[0] * (W + 2) for _ in range(H + 2)], [[0] * (W + 2) for _ in range(H + 2)]
    for x1, x2 in zip(range(1, H + 1), range(H, 0, -1)):
        for y1, y2 in zip(range(W), range(W, 0, -1)):
            if S[x1 - 1][y1 - 1] == ".":  # left and upper sides of S[i][j]
                U[x1][y1] = U[x1 - 1][y1] + 1
                L[x1][y1] = L[x1][y1 - 1] + 1

            if S[x2 - 1][y2 - 1] == ".":  # right and under sides
                D[x2][y2] = D[x2 + 1][y2] + 1
                R[x2][y2] = R[x2][y2 + 1] + 1
    ans = max(
        L[i][j] + R[i][j] + U[i][j] + D[i][j] - 3
        for i in range(1, H + 1)
        for j in range(1, W + 1)
    )
    print(ans)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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

from collections import deque

def main(): 
    H,W = map(int,input().split())
    S = [input().split() for _ in range(H)]
    for i in range(H):
        S[i]=list(S[i][0])
    grid = [[0]*W for _ in range(H)]
    
    for i in range(H):
        l=0
        for j in range(W):
            if S[i][j] == "#":
                for k in range(1,l+1):
                    grid[i][j-k]+=l
                l=0
            else:
                l+=1
        for k in range(1,l+1):
                    grid[i][W-k]+=l
    max=0
    for j in range(W):
        l=0
        for i in range(H):
            if S[i][j] == "#":
                for k in range(1,l+1):
                    grid[i-k][j]+=l
                    if grid[i-k][j] > max:
                        max = grid[i-k][j]
                l=0
            else:
                l+=1
        for k in range(1,l+1):
            grid[H-k][j]+=l
            if grid[H-k][j] > max:
                        max = grid[H-k][j]
    print(max, "time")
if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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

# 横方向maxとなるj
max_empty_yoko = 0
max_idx_yoko = [None, None, None] #[istart, iend, j]
for j, s in enumerate(slist):
  tmp_max_empty = 0
  tmp_max_idxj =[None, None, None]
  for index in range(len(s)):
    if s[index] == '.':
      if tmp_max_empty == 0:
        tmp_max_idxj[0] = index
      tmp_max_empty += 1
    else:
      if max_empty_yoko < tmp_max_empty:
        max_empty_yoko = tmp_max_empty
        max_idx_yoko[0] = tmp_max_idxj[0]
        max_idx_yoko[1] = index-1
        max_idx_yoko[2] = j
      tmp_max_empty = 0
      tmp_max_idxj = [None, None, None]
        

  if max_empty_yoko < tmp_max_empty:
    max_empty_yoko = tmp_max_empty
    max_idx_yoko[0] = tmp_max_idxj[0]
    max_idx_yoko[1] = index-1
    max_idx_yoko[2] = j

      
# 縦方向maxとなるi
max_empty_tate = 0
max_idx_tate = [None, None, None]
for i in range(w):
  tmp_max_empty = 0
  tmp_max_idxi = [None, None, None]
  for j in range(h):
    if slist[j][i] == '.':
      if tmp_max_empty == 0:
        tmp_max_idxi[0] = j
      tmp_max_empty += 1
    else:
      if max_empty_tate < tmp_max_empty:
        max_empty_tate = tmp_max_empty
        max_idx_tate[0] = tmp_max_idxi[0]
        max_idx_tate[1] = j-1
        max_idx_tate[2] = i
      tmp_max_empty = 0
      tmp_max_idxi = [None, None, None]

  if max_empty_tate < tmp_max_empty:
    max_empty_tate = tmp_max_empty
    max_idx_tate[0] = tmp_max_idxi[0]
    max_idx_tate[1] = j
    max_idx_tate[2] = i

# ans
if max_idx_yoko[0] <= max_idx_tate[2] and max_idx_tate[2] <=max_idx_yoko[1]: 
  print(max_empty_yoko+max_empty_tate-1)
else:
  print(max_empty_yoko+max_empty_tate)

Submission status: Wrong Answer

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


def solve(H, W, S):
    grid = [[0] * W for _ in range(H)]
    for y in range(H):
        count = 0
        start = 0
        for x in range(W):
            if S[y][x] == '#':
                for i in range(start, x):
                    grid[y][i] = count
                start = x + 1
                count = 0
            else:
                count += 1
        for i in range(start, W):
            grid[y][i] = count

    ans = 0
    for x in range(W):
        count = 0
        start = 0
        for y in range(H):
            if S[y][x] == '#':
                for i in range(start, y):
                    grid[i][x] += count
                start = y + 1
                count = 0
            else:
                count += 1
        for i in range(start, H):
            if ans < grid[i][x] + count:
                ans = grid[i][x] + count

    return ans - 1


if __name__ == '__main__':
    H, W = map(int, input().split())
    S = [input().strip() for _ in range(H)]

    ans = solve(H, W, S)

    print(ans)

Submission status: Wrong Answer

Solution code:
# can't AC without numpy, Python array handling with for is SLOW
import sys
import numpy as np
H, W = map(int, input().split())
S = [list(line.strip("\n")) for line in sys.stdin]
S = (np.array(S) == ".") * 1

# i行j列に置いたとき上下左右の方向それぞれに光の軌跡が何マス伸びるか(自マスを含む)
trailLeft = np.zeros((H, W), dtype=int)
trailRight = np.zeros((H, W), dtype=int)
trailUp = np.zeros((H, W), dtype=int)
trailDown = np.zeros((H, W), dtype=int)

for i in range(H):
    if i == 0:
        trailUp[i] = S[i]
        trailDown[H - i - 1] = S[H - i - 1] * 1
    else:
        trailUp[i] = (trailUp[i - 1] + 1) * S[i]
        trailDown[H - i - 1] = (trailDown[H - i] + 1) * S[i]

for j in range(W):
    if j == 0:
        trailLeft[:, j] = S[:, j]
        trailRight[:, W - j - 1] = S[:, W - j - 1] * 1
    else:
        trailLeft[:, j] = (trailLeft[:, j - 1] + 1) * S[:, j]
        trailRight[:, W - j - 1] = (trailRight[:, W - j] + 1) * S[:, j]

print(np.max(trailLeft + trailRight + trailUp + trailDown - 3))

Submission status: Wrong Answer

Solution code:
import sys
H, W = map(int, input().split())
S = [line.strip("\n") for line in sys.stdin]

# i行j列に置いたとき上下左右の方向それぞれに光の軌跡が何マス伸びるか(自マスを含む)
trailLeft = [[0] * W for _ in range(H)]
trailRight = [[0] * W for _ in range(H)]
trailUp = [[0] * W for _ in range(H)]
trailDown = [[0] * W for _ in range(H)]

for i in range(H):  # 各行について下に見ていく
    for j in range(W):  # その行の各列について右に見ていく
        if S[i][j] == '#':
            pass  # そのマスに置いたとき照らすのは0マス(置けないので)
        else:
            if i == 0 and j == 0:  # 左上
                trailLeft[i][j] = 1
                trailUp[i][j] = 1
            elif i == 0:  # 最上行
                trailLeft[i][j] = trailLeft[i][j - 1] + 1
                trailUp[i][j] = 1
            elif j == 0:  # 最左列
                trailLeft[i][j] = 1
                trailUp[i][j] = trailUp[i - 1][j] + 1
            else:
                trailLeft[i][j] = trailLeft[i][j - 1] + 1
                trailUp[i][j] = trailUp[i - 1][j] + 1

        k = H - i - 1  # H-1 to 0
        l = W - j - 1  # W-1 to 0
        # 左上に見ていく
        if S[k][l] == "#":
            pass
        else:
            if k == H - 1 and l == W - 1:  # 右下
                trailRight[k][l] = 1
                trailDown[k][l] = 1
            elif k == H - 1:  # 最下行
                trailRight[k][l] = trailRight[k][l + 1] + 1
                trailDown[k][l] = 1
            elif l == W - 1:  # 最右列
                trailRight[k][l] = 1
                trailDown[k][l] = trailDown[k + 1][l] + 1
            else:
                trailRight[k][l] = trailRight[k][l + 1] + 1
                trailDown[k][l] = trailDown[k + 1][l] + 1

ans = 0
print(ans)  # 時間計測用のWA解

Submission status: Wrong Answer

Solution code:
import sys
H, W = map(int, input().split())
S = [line.strip("\n") for line in sys.stdin]
transposeS = ["" for _ in range(W)]

rowRunLength = [[None] * W for _ in range(H)]
columnRunLength = [[None] * H for _ in range(W)]


for idx, elem in enumerate(S):
    previousObstacleIndex = -1

    while previousObstacleIndex != W:
        obstacleIndex = elem.find("#", previousObstacleIndex + 1)
        if obstacleIndex == -1:
            obstacleIndex = W
        else:
            rowRunLength[idx][obstacleIndex] = 0
        for lightenedIndex in range(previousObstacleIndex + 1, obstacleIndex):
            rowRunLength[idx][lightenedIndex] = obstacleIndex - previousObstacleIndex - 1
        previousObstacleIndex = obstacleIndex

for i in range(W):
    for j in range(H):
        transposeS[i] += S[j][i]

for idx, elem in enumerate(transposeS):
    print(elem)
    previousObstacleIndex = -1

    while previousObstacleIndex != H:
        obstacleIndex = elem.find("#", previousObstacleIndex + 1)
        if obstacleIndex == -1:
            obstacleIndex = H
        else:
            columnRunLength[idx][obstacleIndex] = 0
        for lightenedIndex in range(previousObstacleIndex + 1, obstacleIndex):
            columnRunLength[idx][lightenedIndex] = obstacleIndex - previousObstacleIndex - 1
        previousObstacleIndex = obstacleIndex

ans = 0
for i in range(H):
    for j in range(W):
        if S[i][j] == ".":
            ans = max(ans, rowRunLength[i][j] + columnRunLength[j][i] - 1)

print(ans)

Submission status: Wrong Answer

Solution code:
h, w = map(int, input().split())
s = []
s_h = []
for _ in range(h):
    k = list(input())
    s.append(k)
    s_h.append(k.count("."))
s_k = list(map(list, zip(*s)))
s_k = list(map(lambda x: x.count("."), s_k))

a = []
for hh in range(h):
    for ww in range(w):
        if s[hh][ww] == ".":
            ans = s_k[ww] + s_h[hh] - 1
            a.append(ans)
        else:
            a.append(0)
print(max(a))