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

def main():
    H, W = map(int, input().split())
    S = [list(input()) for _ in range(H)]
    
    left = np.zeros([H, W], dtype=np.int) - 1
    right = np.zeros([H, W], dtype=np.int) - 1
    up = np.zeros([H, W], dtype=np.int) - 1
    down = np.zeros([H, W], dtype=np.int) - 1

    for i in range(H):
        for j in range(W):
            if S[i][j] == '.':
                if j == 0:
                    left[i][j] = 0
                else:
                    left[i][j] = left[i][j-1] + 1
                if i == 0:
                    up[i][j] = 0
                else:
                    up[i][j] = up[i-1][j] + 1
            else:
                left[i][j] = -1
                up[i][j] = -1
            
            if S[-1-i][-1-j] == '.':
                if j == 0:
                    right[-1-i][-1-j] = 0
                else:
                    right[-1-i][-1-j] = right[-1-i][-1-(j-1)] + 1
                if i == 0:
                    down[-1-i][-1-j] = 0
                else:
                    down[-1-i][-1-j] = down[-1-(i-1)][-1-j] + 1
            else:
                right[i][j] = -1
                down[i][j] = -1
                
    print(np.max(left+right+up+down) + 1)
main()

Submission status: Wrong Answer

Solution code:
import numpy as np

def main():
    H, W = map(int, input().split())
    S = [list(input()) for _ in range(H)]
    
    left = np.empty([H, W], dtype=np.int)
    right = np.empty([H, W], dtype=np.int)
    up = np.empty([H, W], dtype=np.int)
    down = np.empty([H, W], dtype=np.int)

    for i in range(H):
        for j in range(W):
            if S[i][j] == '.':
                if j == 0:
                    left[i][j] = 0
                else:
                    left[i][j] = left[i][j-1] + 1
                if i == 0:
                    up[i][j] = 0
                else:
                    up[i][j] = up[i-1][j] + 1
            else:
                left[i][j] = -1
                up[i][j] = -1
            
            if S[-1-i][-1-j] == '.':
                if j == 0:
                    right[-1-i][-1-j] = 0
                else:
                    right[-1-i][-1-j] = right[-1-i][-1-(j-1)] + 1
                if i == 0:
                    down[-1-i][-1-j] = 0
                else:
                    down[-1-i][-1-j] = down[-1-(i-1)][-1-j] + 1
            else:
                right[i][j] = -1
                down[i][j] = -1
                
    print(np.max(left+right+up+down) + 1)

main()

Submission status: Wrong Answer

Solution code:
H,W=map(int,input().split(' '))
maze = [list(input()) for i in range(H)]
maze_w=[]
maze_h=[]
for i in maze:
    cnt = 0
    l = 0
    r = 0
    tmp = ''
    for j in i:
        if j != "#":
            cnt += 1
            r += 1
        elif cnt:
            tmp += str(cnt)*cnt+'0'
            l = r+1
            r = r+1
            cnt = 0
        else:
            tmp +='0'
    if cnt:
        tmp +=str(cnt)*cnt
    maze_w.append(list(tmp))

for i in range(W):
    cnt = 0
    h = 0
    t = 0
    tmp = ""
    for j in range(H):
        if maze[j][i]!='#':
            cnt += 1
            t +=1
        elif cnt:
            tmp += str(cnt)*cnt+'0'
            h = t+1
            t = t+1
            cnt = 0
        else:
            tmp += '0'
    if cnt:
        tmp += str(cnt)*cnt
    maze_h.append(list(tmp))
ans = 0
for i in range(H):
    for j in range(W):
        ans = max(ans,int(maze_h[j][i])+int(maze_w[i][j])-1)
print(ans)

Submission status: Wrong Answer

Solution code:
import numpy as np
H,W=map(int,input().split(' '))
maze = np.array([list(input()) for i in range(H)])
maze_w=[]
maze_h=[]
for i in maze:
    cnt = 0
    l = 0
    r = 0
    tmp = ''
    for j in i:
        if j != "#":
            cnt += 1
            r += 1
        elif cnt:
            tmp += str(cnt)*cnt+'0'
            l = r+1
            r = r+1
            cnt = 0
        else:
            tmp +='0'
    if cnt:
        tmp +=str(cnt)*cnt
    maze_w.append(list(tmp))

for i in range(W):
    cnt = 0
    h = 0
    t = 0
    tmp = ""
    for j in maze[:,i]:
        if j!='#':
            cnt += 1
            t +=1
        elif cnt:
            tmp += str(cnt)*cnt+'0'
            h = t+1
            t = t+1
            cnt = 0
        else:
            tmp += '0'
    if cnt:
        tmp += str(cnt)*cnt
    maze_h.append(list(tmp))
ans = 0
for i in range(H):
    for j in range(W):
        ans = max(ans,int(maze_h[j][i])+int(maze_w[i][j])-1)
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter 
from collections import defaultdict
from collections import deque
import math
import itertools
import heapq

import sys
sys.setrecursionlimit(10**6)

#n=int(input())
#n,m=list(map(int,input().split()))
#a=list(map(int,input().split()))
input_list = lambda : list(map(int,input().split()))

h,w=input_list()
a=[[s for s in  input()] for _ in range(h)]
#a=[["." for _ in range(w)] for _ in range(h)]
l=[[0 for _ in range(w)] for _ in range(h)]
r=[[0 for _ in range(w)] for _ in range(h)]
u=[[0 for _ in range(w)] for _ in range(h)]
d=[[0 for _ in range(w)] for _ in range(h)]
for w_i in range(w):
    inv_w=w-w_i-1
    for h_i in range(h):
          
        inv_h=h-h_i-1
        
        if a[h_i][w_i]!="#":
            #left
            if w_i>0 and a[h_i][w_i-1]!="#":
                l[h_i][w_i]=l[h_i][w_i-1]+1
             #up
            if h_i>0 and a[h_i-1][w_i]!="#":
                u[h_i][w_i]=u[h_i-1][w_i]+1

        if a[h_i][inv_w]!="#" and inv_w<w-1 and a[h_i][inv_w+1]!="#":
            r[h_i][w_i]=r[h_i][inv_w+1]+1
            


        #down
        if a[inv_h][w_i]!="#" and inv_h<h-1 and a[inv_h+1][w_i]!="#":
            d[h_i][w_i]=d[inv_h+1][w_i]+1


ans=0
for w_i in range(w):
    for h_i in range(h):
        if a[h_i][w_i]=="#":
            continue
        cal=l[h_i][w_i]+r[h_i][w_i]+u[h_i][w_i]+d[h_i][w_i]+1
        ans=max(ans,cal)

print(ans)

Submission status: Wrong Answer

Solution code:
from collections import Counter 
from collections import defaultdict
from collections import deque
import math
import itertools
import heapq
import sys
sys.setrecursionlimit(10**6)

#n=int(input())
#n,m=list(map(int,input().split()))
#a=list(map(int,input().split()))
input_list = lambda : list(map(int,input().split()))

h,w=input_list()
a=[[s for s in  input()] for _ in range(h)]
#a=[["." for _ in range(w)] for _ in range(h)]
l=[[0 for _ in range(w)] for _ in range(h)]
r=[[0 for _ in range(w)] for _ in range(h)]
u=[[0 for _ in range(w)] for _ in range(h)]
d=[[0 for _ in range(w)] for _ in range(h)]
for w_i in range(w):
    for h_i in range(h):
        if a[h_i][w_i]=="#":
            continue
        #left
        if w_i>0 and a[h_i][w_i-1]!="#":
            l[h_i][w_i]=l[h_i][w_i-1]+1

        #right
        if w_i<w-1 and a[h_i][w_i+1]!="#":
            r[h_i][w_i]=r[h_i][w_i+1]+1
        #up
        if h_i>0 and a[h_i-1][w_i]!="#":
            u[h_i][w_i]=u[h_i-1][w_i]+1

        #down
        if h_i<h-1 and a[h_i+1][w_i]!="#":
            d[h_i][w_i]=d[h_i+1][w_i]+1



ans=0
for w_i in range(w):
    for h_i in range(h):
        if a[h_i][w_i]=="#":
            continue
        cal=l[h_i][w_i]+r[h_i][w_i]+u[h_i][w_i]+d[h_i][w_i]+1
        ans=max(ans,cal)

print(ans)

Submission status: Wrong Answer

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

def how_many_bright(x,y):
    global S
    yoko = S[y]
    tate = [r[x] for r in S]
    i = 0
    y_c = 0
    Y_bright = [0,0]
    for ye in yoko:
        if i > y:
            y_c = 1
        if ye == ".":
            Y_bright[y_c]+=1
        else:
            if y_c == 0:
                Y_bright[y_c]=0
            else:
                break
        i+=1
    j = 0
    x_c = 0
    X_bright = [0,0]
    for te in tate:
        if j > x:
            x_c = 1
        if te == ".":
            X_bright[x_c]+=1
        else:
            if x_c == 0:
                X_bright[x_c]=0
            else:
                break

    return sum(X_bright)+sum(Y_bright)-1

max_area = 0
for k in range(w):
    for l in range(h):
        if S[l][k]==".":
            area = how_many_bright(k,l)
            max_area = max(area, max_area)

print(max_area)

Submission status: Wrong Answer

Solution code:
import sys
def input(): return sys.stdin.readline().rstrip()
import numpy as np
def main():
    h,w=map(int,input().split())
    S=[input() for _ in range(h)]
    Sharp=np.ones((h,w),int)
    L=np.zeros((h,w),int)
    R=np.zeros((h,w),int)
    U=np.zeros((h,w),int)
    D=np.zeros((h,w),int)
    for i in range(h):
        for j in range(w):
            if S[i][j]=='#':
                Sharp[i][j]=0
                continue
    D[0,:]=np.ones(w,int)*Sharp[0,:]
    for i in range(1,h-1): 
        D[i,:]=(D[i-1,:]+1)*Sharp[i,:]
    U[h-1,:]=np.ones(w,int)*Sharp[h-1,:]
    for i in range(h-2,-1,-1):
        U[i,:]=(U[i+1,:]+1)*Sharp[i,:]
    L[:,0]=np.ones(h,int)*Sharp[:,0]
    for i in range(1,w-1):
        L[:,i]=(L[:,i-1]+1)*Sharp[:,i]
    R[:,w-1]=np.ones(h,int)*Sharp[:,w-1]
    for i in range(w-2,-1,-1):
        R[:,i]=(R[:,i+1]+1)*Sharp[:,i]
    print(np.max((L+R+U+D)*Sharp+1))


if __name__=='__main__':
    main()

Submission status: Wrong Answer

Solution code:
H, W = map(int, input().split())
S = [[c == "." for c in input()] for _ in range(H)]
to_right = [[0] * W for _ in range(H)]
to_left = [[0] * W for _ in range(H)]
for i in range(H):
    right = 0
    left = 0
    for j in range(W):
        if S[i][j]:
            right += 1
        else:
            right = 0
        to_right[i][j] = right
        if S[i][-j]:
            left += 1
        else:
            left = 0
        to_left[i][-j] = left
to_bottom = [[0] * W for _ in range(H)]
to_top = [[0] * W for _ in range(H)]
for j in range(W):
    bottom = 0
    top = 0
    for i in range(H):
        if S[i][j]:
            bottom += 1
        else:
            bottom = 0
        to_bottom[i][j] = bottom
        if S[-i][j]:
            top += 1
        else:
            top = 0
        to_top[-i][j] = top
ans = 0
for i in range(H):
    right = 0
    left = 0
    for j in range(W):
        if not S[i][j]:
            continue
        ans = max(ans, sum((to_right[i][j], to_left[i][j], to_bottom[i][j], to_top[i][j])))
print(ans - 3)

Submission status: Wrong Answer

Solution code:
H, W = map(int, input().split())
S = [[c == "." for c in input()] for _ in range(H)]
to_right = [[0] * W for _ in range(H)]
to_left = [[0] * W for _ in range(H)]
for i in range(H):
    right = 0
    left = 0
    for j in range(W):
        if S[i][j]:
            right += 1
        else:
            right = 0
        to_right[i][j] = right
        if S[i][-j]:
            left += 1
        else:
            left = 0
        to_left[i][-j] = left
to_bottom = [[0] * W for _ in range(H)]
to_top = [[0] * W for _ in range(H)]
for j in range(W):
    bottom = 0
    top = 0
    for i in range(H):
        if S[i][j]:
            bottom += 1
        else:
            bottom = 0
        to_bottom[i][j] = bottom
        if S[-i][j]:
            top += 1
        else:
            top = 0
        to_top[-i][j] = top
ans = 0
for i in range(H):
    right = 0
    left = 0
    for j in range(W):
        if not S[i][j]:
            continue
        ans = max(ans, sum((to_right[i][j], to_left[i][j], to_bottom[i][j], to_top[i][j])))
print(ans - 4)

Submission status: Wrong Answer

Solution code:
import sys
def input(): return sys.stdin.readline().rstrip()
import numpy as np
def main():
    h,w=map(int,input().split())
    S=[input() for _ in range(h)]
    Sharp=np.ones((h,w),int)
    L=np.zeros((h,w),int)
    R=np.zeros((h,w),int)
    U=np.zeros((h,w),int)
    D=np.zeros((h,w),int)
    for i in range(h):
        for j in range(w):
            if S[i][j]=='#':
                Sharp[i][j]=0
                continue
    D[0,:]=np.ones(w,int)*Sharp[0,:]
    for i in range(1,h-1): 
        D[i,:]=(D[i-1,:]+1)*Sharp[i,:]
    U[h-1,:]=np.ones(w,int)*Sharp[h-1,:]
    for i in range(h-2,-1,-1):
        U[i,:]=(U[i+1,:]+1)*Sharp[i,:]
    L[:,0]=np.ones(h,int)*Sharp[:,0]
    for i in range(1,w-1):
        L[:,i]=(L[:,i-1]+1)*Sharp[:,i]
    R[:,w-1]=np.ones(h,int)*Sharp[:,w-1]
    for i in range(w-2,-1,-1):
        R[:,i]=(R[:,i+1]+1)*Sharp[:,i]
    print(max(np.max(L+R+U+D-3),0))


if __name__=='__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys
def input(): return sys.stdin.readline().rstrip()
import numpy as np
def main():
    h,w=map(int,input().split())
    S=[input() for _ in range(h)]
    Sharp=np.ones((h,w),int)
    L=np.zeros((h,w),int)
    R=np.zeros((h,w),int)
    U=np.zeros((h,w),int)
    D=np.zeros((h,w),int)
    for i in range(h):
        for j in range(w):
            if S[i][j]=='#':
                Sharp[i][j]=0
                continue
    D[0,:]=np.ones(w,int)*Sharp[0,:]
    for i in range(1,h-1): 
        D[i,:]=(D[i-1,:]+1)*Sharp[i,:]
    U[h-1,:]=np.ones(w,int)*Sharp[h-1,:]
    for i in range(h-2,-1,-1):
        U[i,:]=(U[i+1,:]+1)*Sharp[i,:]
    L[:,0]=np.ones(h,int)*Sharp[:,0]
    for i in range(1,w-1):
        L[:,i]=(L[:,i-1]+1)*Sharp[:,i]
    R[:,w-1]=np.ones(h,int)*Sharp[:,w-1]
    for i in range(w-2,-1,-1):
        R[:,i]=(R[:,i+1]+1)*Sharp[:,i]
    print(np.max(L+R+U+D-3))


if __name__=='__main__':
    main()

Submission status: Wrong Answer

Solution code:
#標準入力
H, W = map(int, input().split())
grid = []
for i in range(H):
    tmp = input()
    grid.append(tmp)

#グリッドの縦横を別々に調べる
grid_int = [[0] * W for i in range(H)]
for i in range(H):
    count = 0
    for j in range(W):
        if grid[i][j] == '.':
            count += 1
            if j == W - 1:
                for l in range(count + 1):
                    grid_int[i][j-l] = count
        elif grid[i][j] == '#':
            if j == 0:
                continue
            for k in range(count):
                grid_int[i][j- k - 1] = count
            count = 0

for j in range(W):
    count = 0
    for i in range(H):
        if grid[i][j] == '.':
            count += 1
            if i == H - 1:
                for l in range(count + 1):
                    grid_int[i-l][j] += count
        elif grid[i][j] == '#':
            if i == 0:
                continue
            for k in range(count):
                grid_int[i-k-1][j] += count
            count = 0

ans = 0
for i in range(H):
    tmp_max = max(grid_int[i]) - 1
    if ans < tmp_max:
        ans = tmp_max
print(ans)

Submission status: Wrong Answer

Solution code:
# D - Lamp

H, W = map(int, input().split())
M = [[str(m) for m in input()] for _ in range(H)]
U = [[0] * W for _ in range(H)]
L = [[0] * W for _ in range(H)]
D = [[0] * W for _ in range(H)]
R = [[0] * W for _ in range(H)]

for i in reversed(range(H)):
    for j in reversed(range(W)):
        if i == H - 1 and M[i][j] != '#':
            D[i][j] = 1
        if j == W - 1 and M[i][j] != '#':
            R[i][j] = 1
        if i != H - 1 and j != W - 1 and M[i][j] != '#':
            D[i][j] = D[i + 1][j] + 1
            R[i][j] = R[i][j + 1] + 1

mx = 0
for i in range(H):
    for j in range(W):
        if i == 0 and M[i][j] != '#':
            U[i][j] = 1
        if j == 0 and M[i][j] != '#':
            L[i][j] = 1
        if i != 0 and j != 0 and M[i][j] != '#':
            U[i][j] = U[i - 1][j] + 1
            L[i][j] = L[i][j - 1] + 1

        p = U[i][j] + L[i][j] + D[i][j] + R[i][j] - 3
        mx = max(mx, p)

# mx = 0
# for i in range(H):
#     for j in range(H):
#         p = U[i][j] + L[i][j] + D[i][j] + R[i][j] - 3
#         mx = max(mx, p)

print(mx)

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(2147483647)
input = sys.stdin.buffer.readline

h,w=map(int,input().split())
s=list(input() for _ in range(h))

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

def yoko_check(y,x,cnt):
    global yoko,s
    if x==w-1:
        yoko[y][x]=cnt
        return cnt
    else:
        if s[y][x+1]=="#":
            yoko[y][x]=cnt
            return cnt
        else:
            yoko[y][x]=yoko_check(y,x+1,cnt+1)
            return yoko[y][x]


def tate_check(y,x,cnt):
    global tate,s
    if y==h-1:
        tate[y][x]=cnt
        return cnt
    else:
        if s[y+1][x]=="#":
            tate[y][x]=cnt
            return cnt
        else:
            tate[y][x]=tate_check(y+1,x,cnt+1)
            return tate[y][x]


for y in range(h):
    for x in range(w):
        if yoko[y][x]==0 and s[y][x]==".":
            yoko_check(y,x,1)
        if tate[y][x]==0 and s[y][x]==".":
            tate_check(y,x,1)

#print(tate)

result=0
for y in range(h):
    for x in range(w):
        if s[y][x]==".":
            result=max(result,tate[y][x]+yoko[y][x]-1)  

print(result)

Submission status: Wrong Answer

Solution code:
def rle(s):
    n = len(s)
    seq_cnt = 0
    before_c = s[0]
    res = list()
    for i, c in enumerate(s):
        if c == before_c:
            seq_cnt += 1
        else:
            res.append((before_c, seq_cnt))
            before_c = c
            seq_cnt = 1
        if i == n - 1:
            res.append((before_c, seq_cnt))
    return res


def to_seq_num(s):
    rle_res = rle(s)
    res = list()
    for r in rle_res:
        _, seq_num = r
        res.extend([seq_num] * seq_num)
    return res


def main():
    H, W = list(map(int, input().split(' ')))
    field = list()
    for _ in range(H):
        field.append(input())
    horizontal_cells = [[0 for _ in range(W)] for _ in range(H)]
    for h in range(H):
        seq_num = to_seq_num(field[h])
        horizontal_cells[h] = seq_num
    vertical_cells = [[0 for _ in range(W)] for _ in range(H)]
    for w in range(W):
        seq_num = to_seq_num([row[w] for row in field])
        for h in range(H):
            vertical_cells[h][w] = seq_num[h]
    all_cells = [[horizontal_cells[h][w] + vertical_cells[h][w] - 1 for w in range(W)] for h in range(H)]
    max_num = 0
    for h in range(H):
        for w in range(W):
            if all_cells[h][w] > max_num:
                max_num = all_cells[h][w]
    print(max_num)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
D = {".":1,"#":0}
H,W = map(int,input().split())
S = [input().strip() for _ in range(H)]
A = [[[0,0] for _ in range(W)] for _ in range(H)]
for i in range(H):
    cnt = 0
    for j in range(W):
        if S[i][j]=="#":
            cnt = 0
        else:
            cnt += 1
            A[i][j][0] = cnt
for i in range(H):
    for j in range(W-2,-1,-1):
        A[i][j][0] = D[S[i][j]]*max(A[i][j][0],A[i][j+1][0])
for j in range(W):
    cnt = 0
    for i in range(H):
        if S[i][j]=="#":
            cnt = 0
        else:
            cnt += 1
            A[i][j][1] = cnt
cmax = 0
for j in range(W):
    for i in range(H-2,-1,-1):
        A[i][j][1] = D[S[i][j]]*max(A[i][j][1],A[i+1][j][1])
        cmax = max(cmax,A[i][j][0]+A[i][j][1]-1)
print(cmax)

Submission status: Wrong Answer

Solution code:
H,W = map(int,input().split())
S = [input().strip() for _ in range(H)]
A = [[[0,0] for _ in range(W)] for _ in range(H)]
for i in range(H):
    cnt = 0
    for j in range(W):
        if S[i][j]=="#":
            cnt = 0
        else:
            cnt += 1
            A[i][j][0] = cnt
for i in range(H):
    for j in range(W-1,-1,-1):
        if S[i][j]=="." and j+1<W:
            A[i][j][0] = max(A[i][j][0],A[i][j+1][0])
for j in range(W):
    cnt = 0
    for i in range(H):
        if S[i][j]=="#":
            cnt = 0
        else:
            cnt += 1
            A[i][j][1] = cnt
cmax = 0
for j in range(W):
    for i in range(H-1,-1,-1):
        if S[i][j]=="." and i+1<H:
            A[i][j][1] = max(A[i][j][1],A[i+1][j][1])
            cmax = max(cmax,A[i][j][0]+A[i][j][1]-1)
print(cmax)

Submission status: Wrong Answer

Solution code:
h, w=map(int, input().split())
grid = []
dydx = [[0, 1], [1,0], [-1, 0], [0, -1]]
done = [[0]*w for _ in range(h)]
res=0

for i in range(h):
    s = list(input().rstrip())
    grid.append(s)

def search(i , j, vec):
    t=0
    while i+vec[0]<h and j+vec[1]<w and i+vec[0]>-1 and j+vec[1]>-1 and grid[i+vec[0]][j+vec[1]]==".":
        done[i+vec[0]][j+vec[1]]=1
        i+=vec[0]
        j+=vec[1]
        t+=1
    return t;

for i in range(h):
    for j in range(w):
        if(grid[i][j]!="#") and not done[i][j]:
            tmp = 1
            done[i][j]=1
            for vec in dydx:
                tmp+=search(i, j, vec)

            res = max(res, tmp)

print(res)

Submission status: Wrong Answer

Solution code:
h,w=map(int,input().split())
M=[]
ans=[]
for i in range(h):
  M.append(input())
  ans.append([])
  for j in range(w):
    ans[i].append([-1,-1])
max=0
print(max)

Submission status: Wrong Answer

Solution code:
def resolve():
    h, w = map(int, input().split())
    s = [input() for _ in range(h)]
    hs = [[0]*w for _ in range(h)]
    ws = [[0]*w for _ in range(h)]

    for i in range(h):
        cums = 0
        for j in range(w):
            if s[i][j] == "#":
                cums = 0
                ws[i][j] = 0
            else:
                cums += 1
                ws[i][j] = cums
        for j in reversed(range(w-1)):
            if ws[i][j+1] != 0 and ws[i][j] != 0:
                ws[i][j] = ws[i][j+1]

    for i in range(w):
        cums = 0
        for j in range(h):
            if s[j][i] == "#":
                cums = 0
                hs[j][i] = 0
            else:
                cums += 1
                hs[j][i] = cums
        for j in reversed(range(h-1)):
            if hs[j+1][i] != 0 and hs[j][i] != 0:
                hs[j][i] = hs[j+1][i]

    ans = 0
    for i in range(h):
        for j in range(w):
            ans = max(ans, ws[i][j] + hs[i][j])
    print(ans-1)

Submission status: Wrong Answer

Solution code:
import sys
def input(): return sys.stdin.readline().strip()


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

    """まずは縦に何連続かだけ計測"""
    dp = [[0] * W for _ in range(H)]
    # 0列目
    for j in range(W):
        if S[0][j] != '#':
            dp[0][j] = 1
    # dp-part
    for i in range(1, H):
        for j in range(W):
            if S[i][j] != '#':
                dp[i][j] = dp[i - 1][j] + 1
            else:
                num = dp[i - 1][j]
                for k in range(num):
                    dp[i - 1 - k][j] = num
    # last-line
    for j in range(W):
        num = dp[H - 1][j]
        for k in range(num):
            dp[H - 1 - k][j] = num

    for i in range(H):
        print(dp[i])
    print("\n")
    
    """次に横に何連続かを計測"""

    dp2 = [[0] * W for _ in range(H)]
    # 0列目
    for i in range(H):
        if S[i][0] != '#':
            dp2[i][0] = 1
    # dp-part
    for j in range(1, W):
        for i in range(H):
            if S[i][j] != '#':
                dp2[i][j] = dp2[i][j - 1] + 1
            else:
                num = dp2[i][j - 1]
                for k in range(num):
                    dp2[i][j - 1 - k] = num
    # last-line
    for i in range(H):
        num = dp2[i][W - 1]
        for k in range(num):
            dp2[i][W - 1 - k] = num

    for i in range(H):
        print(dp2[i])
    
    ans = 0
    for i in range(H):
        for j in range(W):
            ans = max(ans, dp[i][j] + dp2[i][j] - 1)
    print(ans)



if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
h, w = map(int, input().split())
grid = ['#' * (h + 2)]
for _ in range(h):
    grid.append('#' + input() + '#')
grid.append('#' * (h + 2))
lgrid = {(i, 0): 0 for i in range(1, h + 1)}
rgrid = {(i, w+1): 0 for i in range(1, h + 1)}
dgrid = {(h+1, i): 0 for i in range(1, w + 1)}
ugrid = {(0, i): 0 for i in range(1, w + 1)}
for i in range(1, h+1):
    for j in range(1, w+1):
        if grid[i][j] == '#':
            lgrid[(i, j)] = 0
            rgrid[(i, w+1-j)] = 0
            ugrid[(i, j)] = 0
            dgrid[(h+1-i, j)] = 0
        else:
            lgrid[(i, j)] = lgrid[(i, j - 1)] + 1
            rgrid[(i, w+1-j)] = rgrid[(i, w+2-j)] + 1
            ugrid[(i, j)] = ugrid[(i-1, j)] + 1
            dgrid[(h+1-i, j)] = dgrid[(h+2-i, j)] + 1        
cnt = 0
for i in range(1, h+1):
    for j in range(1, w+1):
        tmp = lgrid[(i,j)]+rgrid[(i,j)]+ugrid[(i,j)]+dgrid[(i,j)] - 3
        cnt = max(cnt, tmp)
print(cnt)

Submission status: Wrong Answer

Solution code:
def main():
    import copy
    h,w = map(int,input().split())
    import numpy as np
    mp = np.zeros((h,w))
    for i in range(h):
        s = list(map(lambda x:1 if x=='.' else 0,input()))
        mp[i] += np.array(s)
    mp_c = copy.copy(mp)
    for i in range(h):
        for j in range(w):
            if mp[i][j]==0:
                continue
            if j > 0:
                if mp[i][j-1]>0:
                    mp[i][j] = mp[i][j-1]
                else:
                    for k in range(j+1,w):
                        if mp[i][k]>0:
                            mp[i][j]+=1
                        else:
                            break
            else:
                for k in range(j+1,w):
                    if mp[i][k]>0:
                        mp[i][j]+=1
                    else:
                        break
    for i in range(h):
        for j in range(w):
            if mp_c[i][j]==0:
                continue
            if i>0:
                if mp_c[i-1][j]>0:
                    mp_c[i][j]=mp_c[i-1][j]
                else:
                    for k in range(i+1,h):
                        if mp_c[k][j]>0:
                            mp_c[i][j]+=1
                        else:
                            break
            else:
                for k in range(i+1,h):
                    if mp_c[k][j]>0:
                        mp_c[i][j]+=1
                    else:
                        break
    print(np.max(mp_c+mp-np.ones((h,w))))
                


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
H, W = map(int, input().split())
S = [list(input()) for _ in range(H)]
cnt1 = [[0]*W for _ in range(H)]
for i in range(H):
  for j in range(W):
    if S[i][j] == '#':
      continue
    cnt1[i][j] = 1

for i in range(H):
  for j in range(W):
    if S[i][j] == '#':
      continue
    if j-1 >= 0:
      cnt1[i][j] += cnt1[i][j-1]
for i in range(H):
  for j in range(W-1, -1, -1):
    if S[i][j] == '#':
      continue
    if j+1 <= W-1:
      cnt1[i][j] = max(cnt1[i][j], cnt1[i][j+1])

S2 = [[0]*H for _ in range(W)]
for i in range(H):
  for j in range(W):
    if S[i][j] == '.':
      S2[j][i] = 1

cnt2 = [[0]*H for _ in range(W)]
for i in range(W):
  for j in range(H):
    if S2[i][j] == '#':
      continue
    cnt2[i][j] = 1
for i in range(W):
  for j in range(H):
    if S2[i][j] == '#':
      continue
    if j-1 >= 0:
      cnt2[i][j] += cnt2[i][j-1]
for i in range(W):
  for j in range(H-1, -1, -1):
    if S2[i][j] == '#':
      continue
    if j+1 <= H-1:
      cnt2[i][j] = max(cnt2[i][j], cnt2[i][j+1])

ans = 0
for i in range(H):
  for j in range(W):
    ans = max(ans, cnt1[i][j]+cnt2[j][i]-1)
print(ans)

Submission status: Wrong Answer

Solution code:
import numpy as np

h, w = map(int, input().split())
S = list(list(input()) for _ in range(h))
S = np.array(S)

def get_dp(d, pos, width, height):
  dp = np.zeros_like(d, dtype=int)
  for y in range(height):
    s = 0
    obs_pos = pos[y][d[y]=='#'].tolist()+[width]
    for p in obs_pos:
      dp[y][s:p] = p-s
      s = p+1
  return dp

pos = np.array([[i for i in range(w)]]*h)
dp_row = get_dp(S, pos, w, h)
dp_col = get_dp(S.T, pos.T, h, w)
print((dp_row+dp_col.T).max() - 1)

Submission status: Wrong Answer

Solution code:
def convert(L):
    H=len(L)
    W=len(L[0])
    dp = [[0 for _ in range(W)] for _ in range(H)]
    #dp = np.zeros((L.shape[0],L.shape[1]), dtype='int')
    for i in range(H):
        l=L[i]
        for j in range(W):
            if l[j]:
                if j == 0:
                    dp[i][j] = 1
                else:
                    dp[i][j] = dp[i][j-1] + 1
            else:
                dp[i][j] = 0
    return dp
H,W=map(int,input().split())
L= [[] for _ in range(H)]
for i in range(H):
    L[i]=list(map(lambda x: False if x=="#" else True,list(input()) ))

def rr(matrix):
    return list(map(list, zip(*matrix)))[::-1]

def mir(L):
    return [list(l[::-1]) for l in L]
def flip(L):
    H=len(L)
    W=len(L[0])
    return [[L[i][j] for i in range(H)] for j in range(W)]
A=rr(L)
B=rr(rr(L))
C=rr(rr(rr(L)))
LL=convert(L)
#AA=rr(rr(rr(convert(A))))
#BB=rr(rr(convert(B)))
#CC=rr(convert(C))
#K=flip(L)
ans = -1
M=[[0for j in range(W)] for i in range(H)]
for i in range(H):
    for j in range(W):
        t = LL[i][j] #+ AA[i][j]+BB[i][j]+CC[i][j]-3 
        ans = max(ans,t)
        M[i][j] = t
print(ans)

Submission status: Wrong Answer

Solution code:
import numpy as np
 
def convert(L):
    dp = np.zeros((L.shape[0],L.shape[1]), dtype='int')
    for i in range(L.shape[0]):
        l=L[i]
        for j in range(L.shape[1]):
            if l[j]:
                if j == 0:
                    dp[i][j] = 1
                else:
                    dp[i][j] = dp[i][j-1] + 1
            else:
                dp[i][j] = 0
    return dp
H,W=map(int,input().split())
L= np.zeros((H,W),dtype='bool')
for i in range(H):
    L[i]=list(map(lambda x: False if x=="#" else True,list(input()) ))
 
ans = convert(L) #+ np.fliplr(convert(np.fliplr(L))) + convert(L.T).T + np.flipud(convert(np.flipud(L).T).T) - 3
print(np.max(ans))