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: Runtime Error

Solution code:
def resolve():
    import numpy as np
    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)
resolve()

Submission status: Runtime Error

Solution code:
h,w=map(int,input().split())
reti=[]
for i in range(w+1):
    reti.append("#")
s=[reti]
for i in range(h):
    retu=list(input())
    s.append(["#"]+retu)
def l(i,j):
    if s[i][j]=="#":
        return 0
    elif j==1:
        return 1
    else:
        return l(i,j-1)+1
def r(i,j):
    if s[i][j]=="#":
        return 0
    elif j==w:
        return 1
    else:
        return r(i,j+1)+1
def u(i,j):
    if s[i][j]=="#":
        return 0
    elif i==1:
        return 1
    else:
        return u(i-1,j)+1
def d(i,j):
    if s[i][j]=="#":
        return 0
    elif i==h:
        return 1
    else:
        return d(i+1,j)+1
m=1
for i in range(1,h+1):
    for j in range(1,w+1):
        if m<l(i,j)+r(i,j)+u(i,j)+d(i,j)-3:
            m=l(i,j)+r(i,j)+u(i,j)+d(i,j)-3
print(m)

Submission status: Runtime Error

Solution code:
h,w=map(int,input().split())
reti=[]
for i in range(w+1):
    reti.append("#")
s=[reti]
for i in range(h):
    retu=list(input())
    s.append(["#"]+retu)

def l(i,j):
    if s[i][j]=="#":
        return 0
    elif j==1:
        return 1
    else:
        return l(i,j-1)+1

def r(i,j):
    if s[i][j]=="#":
        return 0
    elif j==w:
        return 1
    else:
        return r(i,j+1)+1

def u(i,j):
    if s[i][j]=="#":
        return 0
    elif i==1:
        return 1
    else:
        return u(i-1,j)+1

def d(i,j):
    if s[i][j]=="#":
        return 0
    elif i==h:
        return 1
    else:
        return d(i+1,j)+1

def a(i,j):
    if s[i][j]=="#":
        return 0
    else:
        return l(i,j)+r(i,j)+u(i,j)+d(i,j)-3


m=0
for i in range(1,h+1):
    for j in range(1,w+1):
        if m<a(i,j):
            m=a(i,j)

print(m)

Submission status: Runtime Error

Solution code:
h,w=map(int,input().split())
reti=[]
for i in range(w+1):
    reti.append("#")
s=[reti]
for i in range(h):
    retu=list(input())
    s.append(["#"]+retu)
print(*s,sep="\n")

def l(i,j):
    if s[i][j]=="#":
        return 0
    elif j==1:
        return 1
    else:
        return l(i,j-1)+1

def r(i,j):
    if s[i][j]=="#":
        return 0
    elif j==w:
        return 1
    else:
        return r(i,j+1)+1

def u(i,j):
    if s[i][j]=="#":
        return 0
    elif i==1:
        return 1
    else:
        return u(i-1,j)+1

def d(i,j):
    if s[i][j]=="#":
        return 0
    elif i==h:
        return 1
    else:
        return d(i+1,j)+1

def a(i,j):
    if s[i][j]=="#":
        return 0
    else:
        return l(i,j)+r(i,j)+u(i,j)+d(i,j)-3


m=0
for i in range(1,h+1):
    for j in range(1,w+1):
        if m<a(i,j):
            m=a(i,j)

print(m)

Submission status: Runtime Error

Solution code:
import numpy as np
H, W = map(int, input().split())
S = np.array([list(input()) for i in range(H)])
dot_W = []
for i in range(H):
  dot = 0
  dot_l = []
  for j in range(W):
    if j == W-1 and S[i,j]== '.':
      dot += 1
      dot_l.append(dot)
    elif j == W-1 and S[i,j] == '#' and dot > 0:
      dot_l.append(dot)
    elif S[i,j] == '.':
      dot += 1
    elif dot > 0:
      dot_l.append(dot)
      dot = 0    
  dot_W.append(dot_l)
dot_H = []
for i in range(W):
  dot = 0
  dot_l = []
  for j in range(H):
    if j == H-1 and S[j,i]== '.':
      dot += 1
      dot_l.append(dot)
    elif j == H-1 and S[j,i]== '#' and dot > 0:
      dot_l.append(dot)
    elif S[j,i] == '.':
      dot += 1
    elif dot > 0:
      dot_l.append(dot)
      dot = 0      
  dot_H.append(dot_l)
print(np.max(dot_H)[0] + np.max(dot_W)[0] - 1)

Submission status: Runtime Error

Solution code:
h, w = map(int, input().split())
grid = ['#' * (h + 2)]
for _ in range(h):
    grid.append('#' + input() + '#')
grid.append('#' * (h+2))
def right(cnt, i, j):
    if grid[i][j + 1] == '.':
        cnt = right(cnt+1, i, j + 1)
    return cnt
        
def left(cnt, i, j):
    if grid[i][j - 1] == '.':
        cnt = left(cnt + 1, i, j - 1)
    return cnt
        
def up(cnt, i, j):
    if grid[i + 1][j] == '.':
        cnt = up(cnt + 1, i + 1, j)
    return cnt

def down(cnt, i, j):
    if grid[i - 1][j] == '.':
        cnt = down(cnt + 1, i - 1, j)
    return cnt

cnt = 0
for i in range(h):
    for j in range(w):
        if grid[i][j] == '.':
            tmp = 1
            tmp = right(tmp, i, j)
            tmp = left(tmp, i, j)
            tmp = up(tmp, i, j)
            tmp = down(tmp, i, j)
            cnt = max(cnt, tmp)
print(cnt)

Submission status: Runtime Error

Solution code:
from collections import deque
H, W = map(int, input().split())
S = [['#'] * (W + 2)]
for _ in range(H):
    tmp = ['#'] + list(input()) + ['#']
    S.append(tmp)
S.append(['#'] * (W + 2))
#迷路の周りを全て壁で覆うことでどの場所からでも四方に探索できるようにした
move = [[1, 0], [-1, 0], [0, 1], [0, -1]]#上下左右どこかに1マス移動する
ans = 0
# スタート位置を変えながら全探索
for X in range(1, H + 1):
    for Y in range(1, W + 1):
        if S[X][Y] == '#':
            continue
#if ~ continue分はtrueなら下の操作を行うことなく次の番号に移るという意味
        check = [[-1] * (W + 2) for _ in range(H + 2)]
        check[X][Y] = 0
#cheakには壁には-1、道にはそこまでの距離、未探索地には0を入れる
        que = deque()
        que.append([X, Y])
        while que:
            tmp = que.popleft()
            x = tmp[0]
            y = tmp[1]
            flag = True
            for dx, dy in move:
                nx = x + dx
                ny = y + dy
                if S[nx][ny] == '.' and check[nx][ny] == -1:#次の移動場所が"道"かつ"未探索"ならqueに突っ込む
                    que.append([nx, ny])
                    check[nx][ny] = check[x][y] + 1 #cheakにそこまでの距離を代入
                    flag = False
#flagの使い方が上手、真似したい
            if flag:#ある一点のスタート地点からの探索がすべて終わってから、その中の
                ans = max(ans, check[x][y])

print (ans)

Submission status: Runtime Error

Solution code:
# solution

import numpy as np
n,m = map(int,input().split())
ar = np.array([list(input()) for _ in range(h)]) == '.'
l = np.zeros((n,m),dtype=int)
r = np.zeros((n,m),dtype=int)
u = np.zeros((n,m),dtype=int)
d = np.zeros((n,m),dtype=int)

for i in range(n):
  u[i] = (u[i-1]+1)*ar[i]
  d[-i-1] = (d[-i]+1)*ar[-i-1]
  
for j in range(m):
  l[:,j] = (l[:,j-1]+1)*ar[:,j]
  r[:,-j-1] = (r[:,-j]+1)*ar[:,-j-1]
print(np.max(u+d+l+r)-3)

Submission status: Runtime Error

Solution code:
import re

H, W = map(int, input().split())
S_list = [list(input()) for _ in range(H)]

l_count = [[i.span()[0] for i in re.finditer('#', s+'#')] for s in S_list]

r_count = [[i.span()[0] for i in re.finditer('#', ''.join(s)+'#')] for s in list(zip(*S_list))]

ans = 0
    
for h in range(H):
    for w in range(W):
        if line[h][w] == '.':
            l_light = 0
            r_light = 0
            for l in l_count[h]:
                if(w < l):
                    l_light = l - l_light
                    break
                l_light = l+1
            for r in r_count[w]:
                if(h < r):
                    r_light = r - r_light
                    break
                r_light = r+1
            
            ans = max(ans, l_light+r_light-1)

print(ans)

Submission status: Runtime Error

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: Runtime Error

Solution code:
import numpy as np
 
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: Runtime Error

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

S_l = [[0] * w for _ in range(h)]
S_r = [[0] * w for _ in range(h)]
S_u = [[0] * w for _ in range(h)]
S_d = [[0] * w for _ in range(h)]

for i in range(h):
    cnt = 0
    for j in range(w):
        if S[i][j] == '.':
            if cnt == 0:
                S_l[i][j] = 1
                cnt = 1
            else:
                S_l[i][j] = S_l[i][j-1] + 1
        else:
            cnt = 0
            S_l[i][j] = 0

for i in range(h):
    cnt = 0
    for j in reversed(range(w)):
        if S[i][j] == '.':
            if cnt == 0:
                S_r[i][j] = 1
                cnt = 1
            else:
                S_r[i][j] = S_r[i][j+1] + 1
        else:
            cnt = 0
            S_r[i][j] = 0

for j in range(w):
    cnt = 0
    for i in range(h):
        if S[i][j] == '.':
            if cnt == 0:
                S_u[i][j] = 1
                cnt = 1
            else:
                S_u[i][j] = S_u[i-1][j] + 1
        else:
            cnt = 0
            S_u[i][j] = 0

ans = 0

for j in range(w):
    cnt = 0
    for i in reversed(range(h)):
        if S[i][j] == '.':
            if cnt == 0:
                S_d[i][j] = 1
                cnt = 1
            else:
                S_d[i][j] = S_d[i+1][j] + 1
        else:
            cnt = 0
            S_d[i][j] = 0
        ans = max(ans, S_l[i][j] + S_r[i][j] + S_u[i,j] + S_d[i][j] - 3)

print(ans)

Submission status: Runtime Error

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

S_l = [[0] * w for _ in range(h)]
S_r = [[0] * w for _ in range(h)]
S_u = [[0] * w for _ in range(h)]
S_d = [[0] * w for _ in range(h)]

for i in range(h):
    cnt = 0
    for j in range(w):
        if S[i][j] == '.':
            if cnt == 0:
                S_l[i][j] = 1
                cnt = 1
            else:
                S_l[i][j] = S_l[i][j-1] + 1
        else:
            cnt = 0
            S_l[i][j] = 0

for i in range(h):
    cnt = 0
    for j in reversed(range(w)):
        if S[i][j] == '.':
            if cnt == 0:
                S_r[i][j] = 1
                cnt = 1
            else:
                S_r[i][j] = S_r[i][j+1] + 1
        else:
            cnt = 0
            S_r[i][j] = 0

for j in range(w):
    cnt = 0
    for i in range(h):
        if S[i][j] == '.':
            if cnt == 0:
                S_u[i][j] = 1
                cnt = 1
            else:
                S_u[i][j] = S_u[i-1][j] + 1
        else:
            cnt = 0
            S_u[i][j] = 0

ans = 0

for j in range(w):
    cnt = 0
    for i in reversed(range(h)):
        if S[i][j] == '.':
            if cnt == 0:
                S_d[i][j] = 1
                cnt = 1
            else:
                S_d[i][j] = S_d[i+1][j] + 1
        else:
            cnt = 0
            S_d[i][j] = 0
         ans = max(ans, S_l[i][j] + S_r[i][j] + S_u[i,j] + S_d[i][j] - 3)

print(ans)

Submission status: Runtime Error

Solution code:
import itertools
import math
import string
import collections
from collections import Counter
from collections import deque
import sys
sys.setrecursionlimit(2*10**5)
INF = 2**60


def readints():
    return list(map(int, input().split()))


def nCr(n, r):
    return math.factorial(n)//(math.factorial(n-r)*math.factorial(r))


def has_duplicates2(seq):
    seen = []
    for item in seq:
        if not(item in seen):
            seen.append(item)
    return len(seq) != len(seen)


def divisor(n):
    divisor = []
    for i in range(1, n+1):
        if n % i == 0:
            divisor.append(i)
    return divisor


# coordinates
dx = [-1, -1, -1, 0, 0, 1, 1, 1]
dy = [-1, 0, 1, -1, 1, -1, 0, 1]


N, M = map(int, input().split())
a = []
memo = [0]*(N+1)
for _ in range(M):
    a.append(int(input()))

safe = [True]*(N+1)
for i in range(M):
    safe[(a[i])] = False


def func(i):
    global safe
    if memo[i] != 0:
        return memo[i]

    if not(safe[i]):
        return 0
    if i == 0:
        return 1
    if i == 1:
        return 1
    ret = 0
    if i >= 2:
        ret += func(i-1)+func(i-2)
        memo[i] = ret
        return ret


print(func(N) % 1000000007)

Submission status: Runtime Error

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.int)
    sw = np.zeros((W, H),dtype=np.int)

    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: Runtime Error

Solution code:
# coding: utf-8

import sys
import math
import collections
import itertools
INF = 10 ** 13
MOD = 10 ** 9 + 7
def input() : return sys.stdin.readline().strip()
def gcd(x, y) : return y if x % y == 0 else gcd(y, x % y)
def lcm(x, y) : return (x * y) // gcd(x, y)
def I() : return int(input())
def LI() : return [int(x) for x in input().split()]
def RI(N) : return [int(input()) for _ in range(N)]
def LRI(N) : return [[int(x) for x in input().split()] for _ in range(N)]
def LS() : return input().split()
def RS(N) : return [input() for _ in range(N)]
def LRS(N) : return [input().split() for _ in range(N)]
def PL(L) : print(*L, sep="\n")

H, W = LI()
S = RS(H)

def dfs(x, y, ok, dist):
    if not(0 <= x < W) or not(0 <= y < H) or S[y][x] == "#":
        return ok - 1

    if dist == 1:
        return dfs(x, y-1, ok+1, 1)
    elif dist == 2:
        return dfs(x+1, y, ok+1, 2)
    elif dist == 3:
        return dfs(x, y+1, ok+1, 3)
    else:
        return dfs(x-1, y, ok+1, 4)

ans = 0
for x in range(W):
    for y in range(H):
        if S[y][x] == ".":
            ans = max(ans, 1 + dfs(x, y-1, 1, 1) + dfs(x+1, y, 1, 2) + dfs(x, y+1, 1, 3) + dfs(x-1, y, 1, 4))

print(ans)

Submission status: Runtime Error

Solution code:
def main():
    h,w=map(int,input().split())
    s=[list(input()) for _ in range(h)]
    d=[[0,-1],[0,1],[-1,0],[1,0]]

    def chk(H,W,DX,DY):
        if H+DX<0 or H+DX>h-1 or W+DY<0 or W+DY>w-1:
            return 0
        elif s[H+DX][W+DY]=='#':
            return 0
        else:
            return 1+chk(H+DX,W+DY,DX,DY)
    ans=0
    for i in range(h):
        for j in range(w):
            cnt=1
            if s[i][j]=='#':
                continue
            for dx,dy in d:
                cnt+=chk(i,j,dx,dy)
            ans=max(ans,cnt)
    print(ans)
    
if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
from collections import deque
from copy import deepcopy
import sys

def main():
    input = sys.stdin.readline

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

    s = []
    s.append(['#' for _ in range(w+2)])
    for _ in range(h):
        s.append(list('#'+input()+'#'))
    s.append(['#' for _ in range(w+2)])

    q = deque()
    dp = [[[0,0] for _ in range(w+2)]for _ in range(h+2)]

    def yoko(x,y):
        global q
        global s
        s[y][x] = '#'
        res = 0
        q.append([x,y])

        while q:
            x,y = q.popleft()
            if s[y][x-1] == '.':
                q.append([x-1,y])
                res += 1
                s[y][x-1] = '#'
            if s[y][x+1] == '.':
                q.append([x+1,y])
                res += 1
                s[y][x+1] = '#'

        return res

    def tate(x,y):
        global q
        global s
        s[y][x] = '#'
        res = 0
        q.append([x,y])

        while q:
            x,y = q.popleft()
            if s[y-1][x] == '.':
                q.append([x,y-1])
                res += 1
                s[y-1][x] = '#'
            if s[y+1][x] == '.':
                q.append([x,y+1])
                res += 1
                s[y+1][x] = '#'

        return res

    ans = 0
    tmp = deepcopy(s)
    for i in range(1,h+1):
        for j in range(1,w+1):
            if s[i][j] == '.':
                if s[i-1][j] == '.' and s[i][j-1] == '.':
                    ans = max(ans,dp[i-1][j][0] + dp[i][j-1][1])
                    dp[i][j] = [dp[i-1][j][0],dp[i][j-1][1]]
                elif s[i-1][j] == '.' and s[i][j-1] == '#':
                    response = yoko(j,i)
                    ans = max(ans,dp[i-1][j][0] + response)
                    dp[i][j] = [dp[i-1][j][0],response]
                elif s[i-1][j] == '#' and s[i][j-1] == '.':
                    response = tate(j,i)
                    ans = max(ans,dp[i][j-1][1] + response)
                    dp[i][j] = [response,dp[i][j-1][1]]
                else:
                    t = tate(j,i)
                    y = yoko(j,i)
                    ans = max(t+y,ans)
                    dp[i][j] = [t,y]
                s = deepcopy(tmp)

    print(ans+1)

if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
import sys
input=sys.stdin.readline
H, W = map(int, input().split())
d = []
d2 = []
d3 = []
for h in range(H):
    s = input().strip() + "#"
    d.append(s)
    d2.append(sc(s))

for i in range(W):
    s = ""
    for j in range(H):
        s += d[j][i]
    s += "#"
    d3.append(sc(s))

Submission status: Runtime Error

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

def yoko(h,w,n):
    if w == W-1 or s[h][w+1] == "#":
        ans_y[h][w] = n
        if n != 1: return n
    else:
        num = yoko(h,w+1,n+1)
        ans_y[h][w] = num
        if n != 1: return num

def tate(h,w,n):
    if h == H-1 or s[h+1][w] == "#":
        ans_t[h][w] = n
        if n != 1: return n
    else:
        num = tate(h+1,w,n+1)
        ans_t[h][w] = num
        if n != 1: return num

for h in range(H):
    for w in range(W):
        if s[h][w] == ".":
            if ans_y[h][w] == 0: yoko(h,w,1)
            if ans_t[h][w] == 0: tate(h,w,1)

ans = 0
for h in range(H):
    for w in range(W):
        ans = max(ans, ans_y[h][w] + ans_t[h][w] - 1)

print(ans)

Submission status: Runtime Error

Solution code:
h,w=map(int,input().split())
l=[]
for i in range(w):
    l.append(input())
rowrange=[]
for i in l:
    start=i.find('.')
    for j in range(start+1,w):
        if i[j]=='#':
            rowrange.append((start,j-1))
            start=i.find('.',j)
        elif j==w-1:
            rowrange.append((start,j))
colrange=[]
for i in range(w):
    temp=''
    for j in range(h):
        temp+=l[i][j]
    start=temp.find('.')
    for j in range(start+1,h):
        if temp[j]=='#':
            colrange.append((start,j-1))
            start=temp.find('.',j)
        elif j==h-1:
            colrange.append((start,j))
ans=0
for i in range(h):
    for j in range(w):
        if l[i][j]!='#':
            for r in rowrange:
                if i>=r[0] and i<=r[1]:
                    for c in colrange:
                        if j>=c[0] and j<=c[1]:
                            ans=max(ans,r[1]-r[0]+c[1]-c[0]+1)
print(ans)

Submission status: Runtime Error

Solution code:
import numpy as np
H, W=map(int, input().split())
S=np.array([list(input()) for _ in range(H)])
S=np.where(S==".",1,0 )

left=np.zeros((H, W))
right=np.zeros((H, W))
top=np.zeros((H, W))
bottom=np.zeros((H, W))

for i in range(W):
  if i==0:
    left[:,i]=S[:,i]
    right[:,-i-1]=S[:,-i-1]
  else:
    left[:,i]=(left[:,i-1]+1)*S[:,i]
    right[:,-i-1]=(right[-i]+1)*S[:,-i-1]
    
for i in range(H):
  if i==0:
    top[i,:]=S[i,:]
    bottom[-1-i,:]=S[-i-1,:]
  else:
    top[i,:]=(top[i-1,:]-S[i,:])
    bottom[-1-i,:]=(bottom[-i]+1)*S[-i-1,:]
    
ans=left+top+right+bottom-3
    
    
print(ans.max())

Submission status: Runtime Error

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

# direction definition
# 0: up
# 1: down
# 2: left
# 3: right
grid = [[[-1, -1, -1, -1] for w in range(W)] for h in range(H)]

# Initialize top and bottom sides
for w in range(W):
  grid[0][w][0] = 1
  grid[H-1][w][1] = 1

# Initialize left and right sides
for h in range(H):
  grid[h][0][2] = 1
  grid[h][W-1][3] = 1

# height, width, direction
def dfs(h, w, d):
  if not (0<=h<=H-1 and 0<=w<=W-1):
    return 0
  
  if S[h][w] == "#":
    grid[h][w] = [0, 0, 0, 0]
    return 0

  # up
  if d == 0:
    if grid[h][w][d] == -1:
      grid[h][w][d] = 1 + dfs(h-1, w, d)
    return grid[h][w][d]
  # down
  elif d == 1:
    if grid[h][w][d] == -1:
      grid[h][w][d] = 1 + dfs(h+1, w, d)
    return grid[h][w][d]
  # left
  elif d == 2:
    if grid[h][w][d] == -1:
      grid[h][w][d] = 1 + dfs(h, w-1, d)
    return grid[h][w][d]
  # right
  elif d == 3:
    if grid[h][w][d] == -1:
      grid[h][w][d] = 1 + dfs(h, w+1, d)
    return grid[h][w][d]

ans = 0
for h in range(H):
  for w in range(W):
    if S[h][w] == ".":
      count = 1
      count += dfs(h-1, w, 0)
      count += dfs(h+1, w, 1)
      count += dfs(h, w-1, 2)
      count += dfs(h, w+1, 3)
      if count >= ans:
        ans = count
    
print(ans)

Submission status: Runtime Error

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

counter = [[[0, 0]]*w for i in range(h)]
ans = 0
for i in range(h):
  for j in range(w):
    if grid[i][j] == "#":
      continue
    if i == 0 or grid[i-1][j] == "#":
      k = 0
      while grid[i+k][j] == "." and i+k < n:
        k += 1
      counter[i][j][0] = k
    else:
      counter[i][j][0] = counter[i-1][j][0]
    if j == 0 or grid[i][j-1] == "#":
      k = 0
      while grid[i][j+k] == "." and j+k < n:
        k += 1
      counter[i][j][1] = k
    else:
      counter[i][j][1] = counter[i][j-1][1]
    if ans < counter[i][j][0]+counter[i][j][1]:
      ans = counter[i][j][0]+counter[i][j][1]
print(ans+1)

Submission status: Runtime Error

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

left,right,up,down=[np.zeros((h,w)) for _ in range(4)]
for i in range(w):
    left[:,i]=(left[:,i-1]+1)*S[:,i]
    right[:,-i-1]=(right[:,-i]+1)*S[i,-i-1]
for i in range(h):
    up[i]=(up[i-1]+1)*S[i]
    down[-i-1]=(down[-i]+1)*S[-i-1]

print(np.max(left+right+up+down)-3)

Submission status: Runtime Error

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

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

for i in range(h):
    dot_cnt, beg_sec = 0, 0
    for j in range(w):
        if s[i][j] == '#':
            if dot_cnt > 0:
                for k in range(beg_sec, j):
                    w_cnt[i][k] = dot_cnt
                beg_sec = j+1
                dot_cnt = 0
            else:
                w_cnt[i][j] = 0
                beg_sec += 1
        else:
            dot_cnt += 1
    if dot_cnt > 0:
        for k in range(beg_sec, w):
            w_cnt[i][k] = dot_cnt

for i in range(w):
    dot_cnt, beg_sec = 0, 0
    for j in range(h):
        if s[j][i] == '#':
            if dot_cnt > 0:
                for k in range(beg_sec, j):
                    h_cnt[k][i] = dot_cnt
                beg_sec = j+1
                dot_cnt = 0
            else:
                h_cnt[j][i] = 0
                beg_sec += 1
        else:
            dot_cnt += 1
    if dot_cnt > 0:
        for k in range(beg_sec, h):
            h_cnt[k][i] = dot_cnt

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

Submission status: Runtime Error

Solution code:
import numpy as np
H, W = map(int, input().split())
S = [list('#' * (W + 2))]
for _ in range(H):
    S.append(list('#' + input() + '#'))
S.append(list('#' * (W + 2)))
S = np.array(S)
# print(S)
# print(S.shape)


def f(x, y, dx, dy):
    if S[x + dx, y + dy] == '#':
        return 0
    return f(x + dx, y + dy, dx, dy) + 1


ans = 0
for i in range(1, H + 1):
    for j in range(1, W + 1):
        if S[i, j] != '.':
            continue
        v = 1
        for dx, dy in ((1, 0), (-1, 0), (0, 1), (0, -1)):
            v += f(i, j, dx, dy)
        ans = max(ans, v)
print(ans)

Submission status: Runtime Error

Solution code:
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][starimport 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)t+k] += j-start
            start = j + 1

Submission status: Runtime Error

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

revs=[]
for i in range(h):
    tmp=s[i][::-1]
    revs.append(tmp)

cnta=[]
for i in range(h):
    left=[0]*w
    count = 0
    if s[i][0]=='.':
        left[0]=1
        count+=1

    for j in range(1,w-2):
        if s[i][1]=='.':
            left[j]=left[j-1]+1
            count+=1
        else:
            left[j]=0
            count=0
    cnta.append(left)

cntb=[]

for i in range(h):
    right=[0]*w
    count = 0
    if revs[i][0]=='.':
        right[0]=1
        count+=1

    for j in range(1,w):
        if revs[i][j]=='.':
            right[j]=right[j-1]+1
            count+=1
        else:
            right[j]=0
            count=0
    cntb.append(right)

print(cntb)