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:
def conv(s):
    if s == '.':
        return 1
    else:
        return 0
    
h, w = map(int, input().split())
grid = [list(map(conv, input())) for i in range(h)]

h_conti_max, w_conti_max = 0, 0
for i in range(h):
    w_conti = 0
    for j in range(w):
        if grid[i][j] == 1:
            w_conti += 1
        else:
            if w_conti_max < w_conti:
                w_conti_max = w_conti
            w_conti = 0
    if w_conti_max < w_conti:
        w_conti_max = w_conti
            
for j in range(w):
    h_conti = 0
    for i in range(h):
        if grid[i][j] == 1:
            h_conti += 1
        else:
            if h_conti_max < h_conti:
                h_conti_max = h_conti
            h_conti = 0
    if h_conti_max < h_conti:
        h_conti_max = h_conti
print(h_conti_max + w_conti_max - 1)

Submission status: Wrong Answer

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

tate=[[-1 for _ in range(w)] for _ in range(h)]
yoko=[[-1 for _ in range(w)] for _ in range(h)]

def search(i,j):
    ansij=1

    if(yoko[i][j] == -1):
        xl=j
        while(0<xl and s[i][xl-1]=='.'):
            ansij+=1
            xl-=1
        xr=j
        while(xr<w-1 and s[i][xr+1]=='.'):
            ansij+=1
            xr+=1

        for k in range(xl,xr+1):
            yoko[i][k]=xr-xl+1
    else:
        ansij+=yoko[i][j]

    if(tate[i][j] == -1):
        yu=i
        while(0<yu and s[yu-1][j]=='.'):
            ansij+=1
            yu-=1
        yd=i
        while(yd<h-1 and s[yd+1][j]=='.'):
            ansij+=1
            yd+=1

        for k in range(yu,yd+1):
            tate[k][j]=yd-yu+1
    else:
        ansij+=tate[i][j]

    return ansij

ans=0
for i in range(h):
    for j in range(w):
        if(s[i][j]=='.'):
            ansij=search(i, j)
            if(ans<ansij):
#                print(i,j,ansij)
                ans=ansij

# print("tate")
# for i in range(len(tate)):
#     print(tate[i])
#
# print("yoko")
# for i in range(len(yoko)):
#     print(yoko[i])

print(ans)

Submission status: Wrong Answer

Solution code:
import numpy as np
h, w = map(int,input().split())
map=[list(input()) for _ in range(h)]

map = [[1 if s == '.' else 0 for s in map[i]] for i in range(h)]
map = np.array(map,dtype=int)
l=map.copy()
r=map.copy()
u=map.copy()
d=map.copy()

for i in range(1,h):
    u[i] += u[i-1]
    u[i] *= map[i]
for i in range(h-1, 0, -1):
    d[i-1] += d[i]
    d[i-1] *= map[i-1]
for i in range(w):
    l[:, i] += l[:, i-1]
    l[:, i] *= map[:, i]
for i in range(w-1, 0, -1):
    r[:, i-1] += r[:, i]
    r[:, i-1] *= map[:, i-1]

print((u+d+l+r).max()-3)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
import sys
import numpy as np

def solve(H: int, W: int, S: "List[str]"):
    S = np.array(S)
    sh = np.zeros((H, W),dtype=np.int8)
    sw = np.zeros((W, H),dtype=np.int8)

    for i, a in enumerate(S):
        left = np.arange(1, len(a)+1)
        left[a==0] = 0
        left = np.maximum.accumulate(left)
        a_ = a[::-1]
        right = np.arange(1,len(a)+1)
        right[a_==0] = 0
        right = np.maximum.accumulate(right)
        right = len(a)+1 - right[::-1]
        k = ((right-left) - 1)
        k[a==1] =0
        sh[i] = k

    for i, a in enumerate(S.T):
        left = np.arange(1, len(a)+1)
        left[a==0] = 0
        left = np.maximum.accumulate(left)
        
        right = np.arange(1,len(a)+1)
        right[a[::-1]==0] = 0
        right = np.maximum.accumulate(right)
        right = len(a)+1 - right[::-1]
        k = ((right-left) - 1)
        k[a==1] =0
        sw[i] = k

    print(np.max(sw+sh.T)-1)

    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    H = int(next(tokens))  # type: int
    W = int(next(tokens))  # type: int
    S = [[ int(_.replace(".", "0").replace("#", "1")) for _ in next(tokens)] for _ in range(H)]  # type: "List[str]"
    solve(H, W, S)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys

def read():
    return sys.stdin.readline().rstrip()

def main():
    h, w = map(int, read().split())
    s = [list(read()) for _ in range(h)]
    row = [[0 for _ in range(w)] for _ in range(h)]
    col = [[0 for _ in range(w)] for _ in range(h)]
    for i in range(h):
        c = 0
        for j in range(w):
            if s[i][j] == "#":
                for k in range(j - c, j):
                    row[i][k] = c
                c = 0
            else:
                c += 1
        for k in range(w - c, w):
            row[i][k] = c
    for i in range(w):
        c = 0
        for j in range(h):
            if s[j][i] == "#":
                for k in range(j - c, j):
                    col[k][i] = c
                c = 0
            else:
                c += 1
        for k in range(h - c, h):
            col[k][i] = c
    ans = 0
    for i in range(h):
        for j in range(w):
            ans = max(row[i][j] + col[i][j], ans)
    print(ans)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
H,W=map(int,input().split())
S=[[i for i in list(input())]for _ in range(H)]
X=[]
ans=0
for i in range(H):
    for j in range(W):
        if S[i][j]=="#":
            X.append((i,j))
for i in range(H):
    for j in range(W):
        if S[i][j]==".":
            l=j+1
            r=W-j
            u=i+1
            d=H-i
            for x,y in X:
                if i==x and y<j:
                    l=min(l,abs(y-j))
                elif i==x and j<y:
                    r=min(r,abs(y-j))
                elif y==j and i<x:
                    u=min(u,abs(i-x))
                elif y==j and x<i:
                    d=min(d,abs(i-x))
            count=l+r+u+d-3
            ans=max(ans,count)
print(ans)

Submission status: Wrong Answer

Solution code:
h, w = map(int, input().split())
grid = [['#' for i in range(w+2)]]
for i in range(h):
  grid.append(['#'] + [s for s in str(input())] + ['#'])
grid.append(['#' for i in range(w+2)])

U = [[0 for j in range(w+2)] for i in range(h+2)]
D = [[0 for j in range(w+2)] for i in range(h+2)]
L = [[0 for j in range(w+2)] for i in range(h+2)]
R = [[0 for j in range(w+2)] for i in range(h+2)]

for i in range(1, h+1):
  for j in range(1, w+1):
    if grid[i][j] == '#': continue
    U[i][j] = U[i-1][j] + 1
    L[i][j] = L[i][j-1] + 1
for i in range(h, 0, -1):
  for j in range(w, 0, -1):
    if grid[i][j] == '#': continue
    D[i][j] = D[i+1][j] + 1
    R[i][j] = R[i][j+1] + 1

ans = 0
for i in range(1, h+1):
  for j in range(1, w+1):
    if grid[i][j] == '#': continue
    cnt = U[i][j] + D[i][j] + L[i][j] + R[i][j] - 3
    ans = max(ans, cnt)
    print(i, j, cnt)
print(ans)

Submission status: Wrong Answer

Solution code:
h, w = map(int, input().split())
grid = [['#' for i in range(w+2)]]
for i in range(h):
  grid.append(['#'] + [s for s in str(input())] + ['#'])
grid.append(['#' for i in range(w+2)])

ud = [[0 for j in range(w+2)] for i in range(h+2)]
lr = [[0 for j in range(w+2)] for i in range(h+2)]

for i in range(1, h+1):
  for j in range(1, w+1):
    if grid[i][j] == '#': continue

    if ud[i-1][j] > 0:
      ud[i][j] = ud[i-1][j]
    else:
      cnt = 0
      d = i
      while grid[d][j] != '#':
        cnt += 1
        d += 1
      ud[i][j] = cnt

    if lr[i][j-1] > 0:
      lr[i][j] = lr[i][j-1]
    else:
      cnt = 0
      r = j
      while grid[i][r] != '#':
        cnt += 1
        r += 1
      lr[i][j] = cnt

ans = 0
for i in range(1, h+1):
  for j in range(1, w+1):
    if grid[i][j] == '#': continue
    cnt = ud[i][j] + lr[i][j] - 1
    ans = max(ans, cnt)
    print(i, j, cnt)
print(ans)

Submission status: Wrong Answer

Solution code:
h,w=map(int,input().split())
s=['#'*(w+2)]+['#'+input()+'#' for i in range(h)]+['#'*(w+2)]
ans=[[0]*(w+1)]*(h+1)
for i in range(1,h+1):
  for j in range(1,w+1):
    cou=0
    p=s[i][j]
    i1=i
    j1=j
    while p=='.':
      cou+=1
      j1-=1
      p=s[i1][j1]
    
    p=s[i][j]
    i1=i
    j1=j
    while p=='.':
      cou+=1
      j1+=1
      p=s[i1][j1]
    
    p=s[i][j]
    i1=i
    j1=j
    while p=='.':
      cou+=1
      i1-=1
      p=s[i1][j1]
    
    p=s[i][j]
    i1=i
    j1=j
    while p=='.':
      cou+=1
      i1+=1
      p=s[i1][j1]
    
    if s[i][j]=='#':
      cou=0
    ans[i][j]=cou
print(max(max(ans))-3)

Submission status: Wrong Answer

Solution code:
h,w=map(int,input().split())
s=list(list(input()) for _ in range(h))
continuous=list(list([0,0] for _ in range(w)) for _2 in range(h))
for r in range(h):
    start=-1
    for c in range(w):
        if s[r][c]=="#":
            if start < c-1:
                for temp in range(start+1,c,1):
                    continuous[r][temp][0]=c-start-1
            start=c
        elif c==w-1:
            if start < c-1:
                for temp in range(start+1,c+1,1):
                    continuous[r][temp][0]=c-start

for c in range(w):
    start=-1
    for r in range(h):
        if s[r][c]=="#":
            if start < r-1:
                for temp in range(start+1,r,1):
                    continuous[temp][c][1]=r-start-1
            start=r
        elif r==h-1:
            if start < r-1:
                for temp in range(start+1,r+1,1):
                    continuous[temp][c][1]=r-start

max_sum = max(max(sum(continuous[r][c]) for c in range(w)) for r in range(h))
print(0 if max_sum == 0 else max_sum-1)

Submission status: Wrong Answer

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

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

for h in range(H):
    for w in range(W):
        if S[h][w] == ".":
            L[h + 1][w + 1] = L[h + 1][w] + 1
        i = W - w - 1
        if S[h][i] == ".":
            R[h + 1][i + 1] = R[h + 1][i + 2] + 1

for w in range(W):
    for h in range(H):
        if S[h][w] == ".":
            U[h + 1][w + 1] = U[h][w + 1] + 1
        i = H - h - 1
        if S[i][w] == ".":
            D[i + 1][w + 1] = D[i + 2][w + 1] + 1

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

print(ans)

Submission status: Wrong Answer

Solution code:
#import numpy as np
H, W = map(int, input().split())
S = [0]*H
counth = [[0]*W for _ in range(H)]  
countw = [[0]*W for _ in range(H)]

for i in range(H):
  S[i] = input()
  
for i in range(H):
  for j in range(W):
    if S[i][j]=='.':
      if counth[i][j]==0:
        b=False
        for k in range(j,W):
          if S[i][k]=='#':
            b = True
            break
        if b==False:
          k+=1
        #print(S[i][j:],l)
        counth[i][j:j+k]=[k]*k
      if countw[i][j]==0:
        b=False
        for k in range(i,H):
          if S[k][j]=='#':
            b=True
            break
        if b==False:
          k+=1
        #print(S[i:][j],m)
        for l in range(i,k):
          #print(i,j,l)
          countw[l][j]=k-i
      #print(i,j,count)
#print(count)
maxim = 0
for i in range(H):
  for j in range(W):
    maxim = int(max(maxim,counth[i][j]+countw[i][j]-1))
print(maxim)

Submission status: Wrong Answer

Solution code:
#import numpy as np
H, W = map(int, input().split())
S = [0]*H
counth = [[0]*W for _ in range(H)]  
countw = [[0]*W for _ in range(H)]

for i in range(H):
  S[i] = input()
  
for i in range(H):
  for j in range(W):
    if S[i][j]=='.':
      if counth[i][j]==0:
        b=False
        for k,s in enumerate(S[i][j:]):
          if s=='#':
            b = True
            break
        if b==False:
          k+=1
        #print(S[i][j:],l)
        counth[i][j:j+k]=[k]*k
      if countw[i][j]==0:
        b=False
        for k in range(i,H):
          if S[k][j]=='#':
            b=True
            break
        if b==False:
          k+=1
        #print(S[i:][j],m)
        for l in range(i,k):
          #print(i,j,l)
          countw[l][j]=k
      #print(i,j,count)
#print(count)
maxim = 0
for i in range(H):
  for j in range(W):
    maxim = int(max(maxim,counth[i][j]+countw[i][j]-1))
print(maxim)

Submission status: Wrong Answer

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

for i in range(H):
  S[i] = input()
  
for i in range(H):
  for j in range(W):
    if S[i][j]=='.':
      if count[i,j,0]==0:
        b=False
        for k,s in enumerate(S[i][j:]):
          if s=='#':
            b = True
            break
        if b==False:
          k+=1
        #print(S[i][j:],l)
        count[i,j:j+k,0]=k
      if count[i,j,1]==0:
        b=False
        for k in range(i,H):
          if S[k][j]=='#':
            b=True
            break
        if b==False:
          k+=1
        #print(S[i:][j],m)
        count[i:i+k,j,1]=k
      #print(i,j,count)
#print(count)
maxim = 0
for i in range(H):
  for j in range(W):
    maxim = int(max(maxim,np.sum(count[i][j])-1))
print(maxim)

Submission status: Wrong Answer

Solution code:
h,w = map(int,input().split())
t = [list(input()) for i in range(h)]
a = [[0 for i in range(w)] for j in range(h)]
x = [[0 for i in range(w)] for j in range(h)]
for i in range(h):
  for j in range(w):
    if t[i][j] == "#":
      x[i][j] = -1
    elif j == 0:
      a[i][j] = 0
    else:
      a[i][j] = a[i][j-1]+1
for i in range(h):
  for j in range(w-1,-1,-1):
    if t[i][j] == "#":
      continue
    elif j == w-1:
      x[i][j] += 0
    else:
      x[i][j] = x[i][j+1]+1
      a[i][j] += x[i][j]
x = [[0 for i in range(w)] for j in range(h)]
for i in range(h):
  for j in range(w):
    if t[i][j] == "#":
      x[i][j] = -1
    elif i == 0:
      a[i][j] += 0
    else:
      x[i][j] = x[i-1][j]+1
      a[i][j] += x[i][j]
x = [[0 for i in range(w)] for j in range(h)]
for i in range(h-1,-1,-1):
  for j in range(w):
    if t[i][j] == "#":
      x[i][j] = -1
    elif i == h-1:
      a[i][j] += 0
    else:
      x[i][j] = x[i+1][j]+1
      a[i][j] += x[i][j]
print(max(max(a[i]) for i in range(h)))

Submission status: Wrong Answer

Solution code:
import sys

readline = sys.stdin.readline
h, w = map(int, readline().split())
grid = [readline() for _ in range(h)]
light = [[0] * w for _ in range(h)]

# row
for i in range(h):
    start = -1
    for j in range(w):
        if grid[i][j] == '.' and start == -1:
            start = j
        elif grid[i][j] == '#' and start != -1:
            length = j - start
            light[i][start:j] = [length] * length
            start = -1
    if start != -1:
        length = w - start
        light[i][start:w] = [length] * length
# column
for i in range(w):
    start = -1
    for j in range(h):
        if grid[j][i] == '.' and start == -1:
            start = j
        elif grid[j][i] == '#' and start != -1:
            length = (j - start) // w
            for k in range(start, j):
                light[k][i] += length
    if start != -1:
        length = (w*h - start) // w
        for k in range(start, h):
            light[k][i] += length

ans = max(max(row) for row in light)
print(ans-1)

Submission status: Wrong Answer

Solution code:
H, W = map(int,input().split())
MAP = []
for _ in range(H):
    MAP.append(list(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)]
D = [[0 for i in range(W)] for j in range(H)]
U = [[0 for i in range(W)] for j in range(H)]

for i in range(H):
    for j in range(W):
        if MAP[i][j] == "#":
            pass
        elif i == 0:
            U[i][j] = 1
        elif j == 0:
            L[i][j] = 1
        else:
            U[i][j] = U[i-1][j] + 1
            L[i][j] = L[i][j-1] + 1
        if MAP[H-1-i][W-1-j] == "#":
            pass
        elif i == 0:
            D[H-1-i][W-1-j] = 1
        elif j == 0:
            R[H-1-i][W-1-j] = 1
        else:
            D[H-1-i][W-1-j] = D[H-i][W-1-j] + 1
            R[H-1-i][W-1-j] = R[H-1-i][W-j] + 1

MAX = 0

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

print(MAX)

Submission status: Wrong Answer

Solution code:
H, W = map(int,input().split())
MAP = []
for _ in range(H):
    MAP.append(list(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)]
D = [[0 for i in range(W)] for j in range(H)]
U = [[0 for i in range(W)] for j in range(H)]

for i in range(H):
    for j in range(W):
        if MAP[i][j] == "#":
            pass
        elif i == 0:
            U[i][j] = 1
        elif j == 0:
            L[i][j] = 1
        else:
            U[i][j] = U[i-1][j] + 1
            L[i][j] = L[i][j-1] + 1
        if MAP[H-1-i][W-1-j] == "#":
            pass
        elif i == 0:
            D[H-1-i][W-1-j] = 1
        elif j == 0:
            R[H-1-i][W-1-j] = 1
        else:
            D[H-1-i][W-1-j] = D[H-i][W-1-j] + 1
            R[H-1-i][W-1-j] = R[H-1-i][W-j] + 1

MAX = -1

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

print(MAX)

Submission status: Wrong Answer

Solution code:
import numpy as np
h,w = map(int,input().split())
ans = [[0]*(w+2) for _ in range(h+2)]
grid = []
grid.append(['#']*(w+2))
for _ in range(h):
    s = list(input())
    grid.append(['#'] + s + ['#'])
grid.append(['#']*(w+2))
print(grid)
for i in range(1,h+1):
    for j in range(0,w+2):
        if grid[i][j] == '#':
            if j >= 1:
                for k in range(j-start):
                    ans[i][start+k] += j-start
            start = j + 1
for j in range(1,w+1):
    for i in range(0,h+2):
        if grid[i][j] == '#':
            if i >= 1:
                for k in range(i-start):
                    ans[start+k][j] += i-start
            start = i + 1
print(np.amax(ans)-1)

Submission status: Wrong Answer

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

L=[[0]*w for _ in range(h)]
for i in range(h):
    for j in range(w):
        if M[i][j]=='#':
            L[i][j]=0
        elif j!=0:
            L[i][j]=L[i][j-1]+1
    
R=[[0]*w for _ in range(h)]
for i in range(h):
    for j in range(w):
        if M[i][j]=='#':
            R[i][j]=0
        elif j!=w-1:
            R[i][j]=R[i][j+1]+1

U=[[0]*w for _ in range(h)]
for i in range(h):
    for j in range(w):
        if M[i][j]=='#':
            U[i][j]=0
        elif i!=0:
            U[i][j]=U[i-1][j]+1

D=[[0]*w for _ in range(h)]
for i in range(h):
    for j in range(w):
        if M[i][j]=='#':
            D[i][j]=0
        elif i!=h-1:
            D[i][j]=D[i+1][j]+1

ans=1
for i in range(h):
    for j in range(w):
        if M[i][j]=='#':
            continue
        ans=max(ans,L[i][j]+R[i][j]+U[i][j]+D[i][j]+1)
print(ans)

Submission status: Wrong Answer

Solution code:
import math,itertools,fractions,heapq,collections,bisect,sys,queue,copy

sys.setrecursionlimit(10**7)
inf=10**20
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 [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return input()

def main():
  h,w=LI()
  field=[list(S()) 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):
    for j in range(w):
      if field[i][j]=='#':
        u[i][j]=0
        l[i][j]=0
      else:
        if i!=0:
          u[i][j]=u[i-1][j]+1
        if j!=0:
          l[i][j]=l[i][j-1]+1

  for i in range(h)[::-1]:
    for j in range(w)[::-1]:
      if field[i][j]=='#':
        d[i][j]=0
        r[i][j]=0
      else:
        if i!=h-1:
          d[i][j]=d[i+1][j]+1
        if j!=w-1:
          r[i][j]=r[i][j+1]+1

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

  return ans

# main()
print(main())

Submission status: Wrong Answer

Solution code:
import math,itertools,fractions,heapq,collections,bisect,sys,queue,copy

sys.setrecursionlimit(10**7)
inf=10**20
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 [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return input()

def main():
  h,w=LI()
  field=[list(S()) 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):
    for j in range(w):
      if field[i][j]=='#':
        u[i][j]=0
        l[i][j]=0
      else:
        if i!=0:
          u[i][j]=u[i-1][j]+1
        if j!=0:
          l[i][j]=u[i][j-1]+1

  for i in range(h)[::-1]:
    for j in range(w)[::-1]:
      if field[i][j]=='#':
        d[i][j]=0
        r[i][j]=0
      else:
        if i!=h-1:
          d[i][j]=u[i+1][j]+1
        if j!=w-1:
          r[i][j]=u[i][j+1]+1

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

  return ans

# main()
print(main())

Submission status: Wrong Answer

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

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

L = [[0 for i in range(w)] for j in range(h)]
R = [[0 for i in range(w)] for j in range(h)]
D = [[0 for i in range(w)] for j in range(h)]
U = [[0 for i in range(w)] for j in range(h)]

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

for i in range(h):
    if R[i][-1] == ".":
        R[i][-1] += 1
    for j in range(-2, -w-1, -1):
        if s[i][j]==".":
            R[i][j] += R[i][j+1]+1

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

for i in range(w):
    if s[-1][i] ==".":
        D[-1][i] += 1
    for j in range(-2, -h-1,-1):
        if s[j][i]==".":
            D[j][i] += D[j+1][i]+1
result = []
for i in range(h):
    for j in range(w):
        result.append(L[i][j]+R[i][j]+U[i][j]+D[i][j]-2)

print(max(result))

Submission status: Wrong Answer

Solution code:
h,w=map(int,input().split())
s=[]
for _ in range(h):
    s.append(input())

noi=[-1 for _ in range(h)]
noj=[-1 for _ in range(w)]
noj_temp=[0 for _ in range(w)]

for i in range(h):
    noi_line=0
    for j in range(w):
        if(s[i][j]=='.'):
            noi_line+=1
            noj_temp[j]+=1
        else:
            noi[i]=max(noi[i],noi_line)
            noi_line=0
            noj[j]=max(noj[j],noj_temp[j])
            noj_temp[j]=0

        if(i==h-1):
            noj[j]=max(noj[j],noj_temp[j])
    else:
        noi[i]=max(noi[i],noi_line)
        noi_line=0
print(max(noi)+max(noj)-1)

Submission status: Wrong Answer

Solution code:
import numpy as np

h,w=map(int,input().split())
g = np.array([list(input()) for _ in range(h)])
g = np.where(g=='.',1,0)

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

for i in range(w):
  l[:,i] = (l[:,i-1]+1)*g[:,i]
  r[:,-i-1] = (r[:,-i]+1)*g[:,-i-1]

for i in range(h):
  u[i,:]=(u[i-1,:]+1)*g[i,:]
  d[-i-1,:]=(d[-i,:]+1)*g[i,:]

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

Submission status: Wrong Answer

Solution code:
h, w = map(int, input().split())
s = [input() for _ in range(h)]
c = [[0 for _ in range(w)] for _ in range(h)]

for i in range(h):
    n = 0
    for j in range(w):
        if j != 0:
            if s[i][j] == "." and s[i][j - 1] == "#" and j != w - 1:
                m = j
                n += 1
            elif s[i][j] == "." and j == w - 1:
                if s[i][j - 1] == "#":
                    m = j
                n += 1
                for k in range(n):
                    c[i][m + k] += n
                n = 0
            elif s[i][j] == ".":
                n += 1
                
            elif s[i][j] == "#" and s[i][j - 1] == ".":
                for k in range(n):
                    c[i][m + k] += n
                n = 0
        else:
            if s[i][j] == ".":
                m = 0
                n += 1

for j in range(w):
    n = 0
    for i in range(h):
        if i != 0:
            if s[i][j] == "." and s[i - 1][j] == "#" and i != h - 1:
                m = i
                n += 1
            elif s[i][j] == "." and i == h - 1:
                if s[i - 1][j] == "#":
                    m = i
                n += 1
                for k in range(n):
                    c[m + k][j] += n
                n = 0
            elif s[i][j] == ".":
                n += 1
                
            elif s[i][j] == "#" and s[i - 1][j] == ".":
                for k in range(n):
                    c[m + k][j] += n
                n = 0
        else:
            if s[i][j] == ".":
                m = 0
                n += 1            

ans = 0
for i in range(h):
    for j in range(w):
        if ans < c[i][j] - 1:
            ans = c[i][j] - 1
print(ans)

Submission status: Wrong Answer

Solution code:
import math
import copy
from copy import deepcopy
import sys
import fractions
import numpy as np
from functools import reduce
# import statistics
import heapq
sys.setrecursionlimit(3000)

# input = sys.stdin.readline
# sys.setrecursionlimit(10**6)

# ===FUNCTION===

def getInputInt():
    inputNum = int(input())
    return inputNum


def getInputListInt():
    outputData = []
    inputData = input().split()
    outputData = [int(n) for n in inputData]

    return outputData


def getSomeInputInt(n):
    outputDataList = []
    for i in range(n):
        inputData = int(input())
        outputDataList.append(inputData)

    return outputDataList


def getSomeInputListInt(n):
    inputDataList = []
    outputDataList = []
    for i in range(n):
        inputData = input().split()
        inputDataList = [int(n) for n in inputData]
        outputDataList.append(inputDataList)

    return outputDataList


# ===CODE===
input_num = getInputListInt()

h = input_num[0]
w = input_num[1]

data=[]
for i in range(h):
    tmp = str(input())
    tmp_list = list(tmp)
    data.append(tmp_list)

def saikiU(cnt, i, j):
    if i < 0 or i > h-1: return cnt
    if j < 0 or j > w-1: return cnt
    if data[i][j] == "#": return cnt

    return saikiU(cnt+1, i-1, j)


def saikiD(cnt, i, j):
    if i < 0 or i > h - 1: return cnt
    if j < 0 or j > w - 1: return cnt
    if data[i][j] == "#": return cnt

    return saikiD(cnt + 1, i + 1, j)

def saikiL(cnt, i, j):
    if i < 0 or i > h - 1: return cnt
    if j < 0 or j > w - 1: return cnt
    if data[i][j] == "#": return cnt

    return saikiL(cnt + 1, i, j-1)

def saikiR(cnt, i, j):
    if i < 0 or i > h - 1: return cnt
    if j < 0 or j > w - 1: return cnt
    if data[i][j] == "#": return cnt

    return saikiR(cnt + 1, i, j+1)

ans = 0
for i in range(h):
    for j in range(w):
        if data[i][j] == "#": continue
        tmp_ans = -3
        tmp_ans += saikiU(0, i, j)
        tmp_ans += saikiD(0, i, j)
        tmp_ans += saikiL(0, i, j)
        tmp_ans += saikiR(0, i, j)
        ans = max(ans, tmp_ans)
print(sys.getrecursionlimit())

print(ans)

Submission status: Wrong Answer

Solution code:
h, w = map(int,input().split())
grid = []
for i in range(h):
    grid.append(list(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)]
#Uを決める
for i in range(w):
    if grid[0][i] == '#':
        U[0][i] = 0
    else:
        U[0][i] = 1
for i in range(1,h):
    for j in range(w):
        if grid[i][j] == '#':
            U[i][j] = 0
        else:
            U[i][j] = U[i-1][j] + 1
 #Dを決める
for i in range(w):
    if grid[-1][i] == '#':
        D[-1][i] = 0
    else:
        D[0][i] = 1
for i in range(h-2, -1,-1):
    for j in range(w):
        if grid[i][j] == '#':
            D[i][j] = 0
        else:
            D[i][j] = D[i+1][j] + 1
# R を決める
for i in range(h):
    if grid[i][-1] == '#':
        R[i][-1] = 0
    else:
        R[i][-1] = 1
for i in range(h):
    for j in range(w-2,-1,-1):
        if grid[i][j] == '#':
            R[i][j] = 0
        else:
            R[i][j] = R[i][j+1] + 1
#Lを決める
for i in range(h):
    if grid[i][0] == '#':
        L[i][0] = 0
    else:
        L[i][0] = 1
for i in range(h):
    for j in range(1,w):
        if grid[i][j] == '#':
            L[i][j] = 0
        else:
            L[i][j] = L[i][j-1] + 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] - 2)
print(ans)

Submission status: Wrong Answer

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

num_list=[[0]*w]*h

def calc_num(num_list,s,h,w):
 for i in range(h):
  cnt=0
  s_inx=-1
  p_list=[0]*w
  for j in range(w):
   if s[i][j]=='.':
    if cnt==0:
     s_inx=j

    cnt+=1

    if j==w-1:
     p_list[s_inx:w]=[cnt]*(w-s_inx)
     cnt=0

   elif s_inx!=-1:
    p_list[s_inx:j]=[cnt]*(j-s_inx)
    cnt=0
  num_list[i]=[x+y for x,y in zip(num_list[i],p_list)]

calc_num(num_list,s,h,w)

ss=[]
for i in zip(*s):
 ss.append(i)
num_list_2=[]
for j in zip(*num_list):
 num_list_2.append(j)

calc_num(num_list_2,ss,w,h)

ans=0
for i in num_list_2:
 ans=max(ans,max(i))
print(ans-1)